Difference Between System Call and Library Call

System call and Library call are related to the operating system of a computer. The computer can operate in two modes; namely, user mode and kernel mode. The key difference between system call and library call is that System call is a function provided by the kernel to enter kernel mode to access the hardware resources whereas, library call is a function provided by programming libraries. For example, open () is a system call and fopen () is a library call. When fopen () in C program, uses the stdio.h header library. Then the system call ‘open (),’ is used from the kernel to complete the file opening task.

CONTENTS

1. Overview and Key Difference
2. What is System Call
3. What is Library Call
4. Similarities Between System Call and Library Call
5. Side by Side Comparison – System Call vs Library Call in Tabular Form
6. Summary

What is System Call?

A computer operates in two modes. They are user mode and kernel mode. Some processes are running on a computer system. A process is a program in execution. When application programs are running, the computer is in user mode. If a hardware resource is required, the process sends a request to the kernel, and the computer enters kernel mode. These requests are sent using system calls. The computer is switching between these two modes frequently. When the task is completed, the computer goes back to user mode from kernel mode. This mode transition is known as “context switching.” System calls are an interface between the operating system and user programs.

Figure 01: System Calls

There are various types of system calls. Create, terminate the process, executing the process, allocate and free memory can be done using “Process Control System Calls.” “File Management System Calls” can be used to create, delete, read, write, open, close files. The process requires some resources to complete execution. Requesting and releasing devices are done through “Device Management System Calls.” “Information Management System Calls” can be used to get system data and to get processes and device attributes. Processes are communicating with each other. This communication is done using “Communication System Calls.” Sending status information, creating and deleting communication connections and sending, receiving messages can be done using communication system calls.

What is Library Call?

Library call is a function provided by the programming libraries. Before making a library call, that library should be imported. Library call might depend on the system call.

In C language, these functions can be used in the program by including the header files. Header files are included using preprocessing directive #include. Preprocessor scans the specified file before continuing with the rest of the source file. Some common library functions are as follows, “math.h” library includes functions related to math operations. “stdio.h” library provides functions for performing input and output. “fopen()” opens the file name pointed. “fclose()” closes the file. “printf() is used to send the formatted output to a standard output. “fprintf ()” is used to send the formatted output to a stream. “scanf()” is used to read formatted input from standard input. “stdlib.h” provides functions for memory management and “time.h” provides functions for time and date manipulation.

What is the Similarity Between System Call and Library Call?

  • Both are related to operating system.

What is Difference Between System Call and Library Call?

System Call vs Library Call

A system call is a function provided by the kernel to enter kernel mode to access hardware resources. Library call is a function provided by the programming library.
Mode of Execution
A System call is executed in the kernel mode. A Library call is executed in the user mode.
Mode Switching
A System call switch from user mode to kernel mode. There is no switching from user mode to kernel mode in Library call.
Portability
A System call is not portable. A Library call is portable.

Summary – System Call vs Library Call 

A System call is implemented in the kernel, and a library call is implemented in the user space. The difference between system call and library call is that a system call is a function provided by the kernel to enter kernel mode to access hardware resources and library call is a function provided by programming libraries. Library calls might depend on the system calls to complete the task. open (), fork(), cd() are some examples of system calls.  fopen (), fprintf () are examples of library calls.

Download the PDF Version of System Call vs Library Call

You can download PDF version of this article and use it for offline purposes as per citation note. Please download PDF version here Difference Between System call and Library Call

Reference:

1.Point, Tutorials. “C Header Files.”, Tutorials Point, 1 Nov. 2017. Available here 
2.Santhosh. “System Call v/s Library Function.” A Quest for Knowledge, 19 Aug. 2011. Available here
3.Point, Tutorials. “C Library .”,  Tutorials Point, 19 Sept. 2017. Available here