Saturday 3 December 2016

System calls

       All operating systems provides service points through which programs request services from the kernel. This service request points directly into the kernel called “system calls”.

       The system provides a library APIs that sits between normal programs and the OS, usually an implementation of C library (libc) such as glibc, it provides wrapper functions for the system calls.

       System call implementation requires a control transfer which involves some sort of architecture specific feature.

       A typical way to implement this is to use a software interrupt or trap. Interrupts transfer control to the operating system kernel so software simply needs to set up some register with the system call number needed, and execute the software interrupt.


       The system call functions may put one or more of the C arguments into the general registers and then execute some machine instruction that generates a software interrupt in the kernel.

Library functions
       Library functions are the general purpose functions defined in Section of “Unix programmers Manual”

       These functions are not entry points into the kernel although they may invoke one or more of the kernel functions.

       For example, ‘printf’ may invoke the ‘write’ system call to perform the output but ‘strcpy’ and ‘atoi’ doesn’t invoke the kernel service at all.

Difference between system call and library function
       System call invokes kernel service, library functions may or may be invoke kernel services.

       For eg. Some OS provides separate system call to return the ‘time’ another for ‘data’. Linux uses a single system call that returns the number of seconds since the Epoch: January 1, 1970, coordinated universal time. Converting this value into human readable time and date using local time zone is left to the user process. Routines are provided in the standard C library to handle most cases.

       System calls usually provides minimal interface while library functions often provide more elaborate functionality.

       For e.g. fork()/exec() are the system call to create and execute process where as system/popen are the libray functions with similar simplified functionality.

No comments:

Post a Comment