The main difference between System Call and Library Call is that System call is a request to the kernel to access a resource while library call is a request to use a function defined in a programming library.
The operating system is an interface that allows the application programs to access hardware resources. The kernel is the core of an operating system. The operating system performs major tasks of a computer system such as memory management, process management, securing the data and many more. System call and library call are two terms associated with operating systems. A kernel provides system calls whereas a programming library provides library calls.
Key Areas Covered
1. What is System Call
– Definition, Functionality
2. What is Library Call
– Definition, Functionality
3. Difference Between System Call and Library Call
– Comparison of Key Differences
Context Switching, Kernel, Library Call, Operating System, System Call
What is System Call
There are two modes in a computer system: the kernel mode and the user mode. In kernel mode, the programs can directly access memory and hardware resources. It is a privileged mode than user mode. In user mode, the programs cannot directly access memory and hardware resource. Most programs execute in the user mode. When a program requires memory or a hardware resource, it sends a request to the kernel using a system call. Then, the mode switches from the user mode to the kernel mode. After finishing the task, the mode changes back from kernel mode to user mode. Hence, this mode transition is also called context switching.
Two important system calls in a UNIX system are as follows:
fork() – This system call is used to create a new process while preserving the existing process. When a specific process makes a fork() call, it creates a copy of a process. Therefore, there are two processes. One is the parent process while the created new process is the child process.
exec() – This system call creates a new process and replaces the exiting process with the new process. Therefore, after calling exec(), only the new process exists. In other words, the process that made the system call is destroyed.
What is Library Call
Library call is a request to use a function provided by a programming library. When the programmer uses a specific library call, he must first import the relevant library. In C programming, the programmer can invoke library functions by including the header files in his program. The preprocessor directives (#include) helps to include header files.
The stdio.h header file includes various functions to perform input and output operations. The fopen is used to open a file while fclose is used to close a file. The printf function helps to send a formatted output to a standard output device while scanf function helps to read a formatted input from a standard input device.
Furthermore, the “math.h” header file contains the functions to perform mathematical operations. The “time.h” header file has the functions to perform time and data calculations. The “string.h” header file has functions to perform string manipulations.
Difference Between System Call and Library Call
A system call is a request by the program to the kernel to enter kernel mode to access a resource, while library call is a request made by the program to access a function defined in a programming library. Thus, this explains the main difference between System Call and Library Call.
In system calls, the mode changes from user mode to kernel mode whereas, in library calls, there is no mode switching. Hence, this is an important difference between System Call and Library Call.
Moreover, system calls are not portable while library calls are portable.
Execution speed is also a major difference between System Call and Library Call. Library calls execute faster than system calls.
Overall, System calls have more privileges than library calls.
fork() and exec() are some examples for system calls while fopen(), fclose(), scanf(), prinf() are some examples for library calls.
A system call is implemented in kernel space while a library call is implemented in the user space. The main difference between System Call and Library Call is that System call is a request to the kernel to access a resource while library call is a request to use a function defined in a programming library.
1.“Introduction to System Calls.” Studytonight, Available here.
2.C Standard Library Functions, Available here.
1.” system call interface” By system call interface – (CC BY-SA 4.0) via Commons Wikimedia
Leave a Reply