What are these System calls with respect to Operating Systems?. More simple definition I could give you is that System Calls is the interface between the Operating System and the User Programs. These functions may be vary with respect to the Operating System Type. Systems calls are machine dependent and in Unix Systems System Calls are written in assembly language and there is a library available to initiate those functions within a C program.
When we run our programs mostly in user mode, the programs may need a System service such as writing some buffered data to a file. Then the execution of the User Program put into a TRAP mode and the control is transferred into the Operating System. Then by examining the method called, the kernel will handle the necessary procedures and return the control to the User Program by sending the relevant message.
Here is a example for calling the write data from a buffer into a file.
n = write(fd, buffer, nbytes)
Example write System call |
Lets examine this example write system call. [1] , [2] and [3] step shows that the parameters of the write method is pushed into the stack. See the order which they are pushed into the stack. The rightmost parameter is pushed first followed by others from right to left.
*Reason behind this is that in earlier days when printf method is called the format of the string appears on top of the stack.
Then it comes to the call write and it will execute the library procedure for the write [4]. Then step [5] is to put the system call number for write in a register. Step [6] shows the execution of the TRAP instruction to switch modes, from USER MODE to the KERNEL MODE. Then in the KERNEL MODE it examines the system call number and the relevant system call handler will be pointed via the table indexed all the system calls and the system call handlers [7]. In this moment [8] system call handler runs.
Once the execution completed the control is returned to the USER MODE library procedure [9]. Then the library procedure returns to the user program [10]. To complete the execution it will clear the stack [11].
That is the typical life cycle of a system call. In POSIX systems there are around hundred system calls. System calls are used in various things Process and File management etc.
Hope you got some knowledge in system calls.. See you next time :)
Once the execution completed the control is returned to the USER MODE library procedure [9]. Then the library procedure returns to the user program [10]. To complete the execution it will clear the stack [11].
That is the typical life cycle of a system call. In POSIX systems there are around hundred system calls. System calls are used in various things Process and File management etc.
Hope you got some knowledge in system calls.. See you next time :)
No comments:
Post a Comment