System calls provide an interface between the process and the operating system.
System calls allow user-level processes to request some services from the operating system which process itself is not allowed to do.
In handling the trap, the operating system will enter in the kernel mode, where it has access to privileged instructions, and can perform the desired service on the behalf of user-level process.
It is because of the critical nature of operations that the operating system itself does them every time they are needed.
For example, for I/O a process involves a system call telling the operating system to read or write particular area and this request is satisfied by the operating system.
Types of System calls
1) Process Control:
A running program needs to be able to stop execution either normally or abnormally.
When execution is stopped abnormally, often a dump of memory is taken and can be examined with a debugger.
Following are functions of process control:
i. end, abort
ii. load, execute
iii. create process, terminate process
iv. get process attributes, set process attributes
v. wait for time
vi. wait event, signal event
vii. allocate and free memory
2) File management :
We first need to be able to create and delete files. Either system call requires the name of the file and perhaps some of the file's attributes.
Once the file is created, we need to open it and to use it. We may also read, write, or reposition. Finally, we need to close the file, indicating that we are no longer using it.
We may need these same sets of operations for directories if we have a directory structure for organizing files in the file system.
In addition, for either files or directories, we need to be able to determine the values of various attributes and perhaps to reset them if necessary. File attributes include the file name, a file type, protection codes, accounting information, and so on
create file, delete file
open, close file
read, write, reposition
get and set file attributes
3) Device Management:
A process may need several resources to execute - main memory, disk drives, access to files, and so on. If the resources are available, they can be granted, and control can be returned to the user process. Otherwise, the process will have to wait until sufficient resources are available.
The various resources controlled by the OS can be thought of as devices. Some of these devices are physical devices (for example, tapes), while others can be thought of as abstract or virtual devices (for example, files).
Once the device has been requested (and allocated to us), we can read, write, and (possibly) reposition the device, just as we can with files.
In fact, the similarity between I/O devices and files is so great that many OSs, including UNIX, merge the two into a combined file-device structure.
A set of system calls is used on files and devices. Sometimes, 1/0 devices are identified by special file names, directory placement, or file attributes.
request device, release device
read, write, reposition
get device attributes, set device attributes
logically attach or detach devices
Many system calls exist simply for the purpose of transferring information between the user program and the OS. For example, most systems have a system call to return the current time and date.
Other system calls may return information about the system, such as the number of current users, the version number of the OS, the amount of free memory or disk space, and so on.
In addition, the OS keeps information about all its processes, and system calls are used to access this information. Generally, calls are also used to reset the process information.
get time or date, set time or date
get system data, set system data
get and set process, file, or device attributes
There are two common models of interprocess communication: the message-passing model and the shared-memory model. In the message-passing model, the communicating processes exchange messages with one another to transfer information.
In the shared-memory model, processes use shared memory creates and shared memory attaches system calls to create and gain access to regions of memory owned by other processes.
Recall that, normally, the OS tries to prevent one process from accessing another process's memory. Shared memory requires that two or more processes agree to remove this restriction. They can then exchange information by reading and writing data in the shared areas.
Message passing is useful for exchanging smaller amounts of data, because no conflicts need be avoided. It is also easier to implement than is shared memory for intercomputer communication.
Shared memory allows maximum speed and convenience of communication, since it can be done at memory speeds when it takes place within a computer. Problems exist, however, in the areas of protection and synchronization between the processes sharing memory.
create, delete communication connection
send, receive messages
transfer status information
Attach and Detach remote devices