The interface between a process and an operating system is provided by system calls. In general, system calls are available as assembly language instructions. They are also included in the manuals used by the assembly level programmers. System calls are usually made when a process in user mode requires access to a resource. Then it requests the kernel to provide the resource via a system call.
A figure representing the execution of the system call is given as follows −
As can be seen from this diagram, the processes execute normally in the user mode until a system call interrupts this. Then the system call is executed on a priority basis in the kernel mode. After the execution of the system call, the control returns to the user mode and execution of user processes can be resumed.
In general, system calls are required in the following situations −
There are mainly five types of system calls. These are explained in detail as follows −
These system calls deal with processes such as process creation, process termination etc.
These system calls are responsible for file manipulation such as creating a file, reading a file, writing into a file etc.
These system calls are responsible for device manipulation such as reading from device buffers, writing into device buffers etc.
These system calls handle information and its transfer between the operating system and the user program.
These system calls are useful for interprocess communication. They also deal with creating and deleting a communication connection.
Some of the examples of all the above types of system calls in Windows and Unix are given as follows −
|Types of System Calls||Windows||Linux|
There are many different system calls as shown above. Details of some of those system calls are as follows −
The open() system call is used to provide access to a file in a file system. This system call allocates resources to the file and provides a handle that the process uses to refer to the file. A file can be opened by multiple processes at the same time or be restricted to one process. It all depends on the file organisation and file system.
The read() system call is used to access data from a file that is stored in the file system. The file to read can be identified by its file descriptor and it should be opened using open() before it can be read. In general, the read() system calls takes three arguments i.e. the file descriptor, buffer which stores read data and number of bytes to be read from the file.
The write() system calls writes the data from a user buffer into a device such as a file. This system call is one of the ways to output data from a program. In general, the write system calls takes three arguments i.e. file descriptor, pointer to the buffer where data is stored and number of bytes to write from the buffer.
The close() system call is used to terminate access to a file system. Using this system call means that the file is no longer required by the program and so the buffers are flushed, the file metadata is updated and the file resources are de-allocated.