Why do we need a system call? There are two main reasons.
(1) system calls provide a unified interface for user space to access hardware resources, so that applications do not have to pay attention to specific hardware access operations. For example, when reading and writing files, applications do not have to worry about the disk type, or even the file system.
(2) system calls can protect the system to ensure system stability and security. The existence of system calls specifies the specific way for a user process to enter the kernel. In other words, the path for the user to access the kernel is specified in advance and can only enter the kernel from the specified location, rather than jumping into the kernel. With this unified access path restriction, You can ensure kernel security.
(3) system calls have stronger functions.
Differences between system calls and library functions:
1. system calling is used to facilitate the application to use the interface of the operating system, and library functions are used to facilitate the compilation of applications. For example, you can compile a function by yourself, which can be called a library function.
2. system calls can be understood as the interface functions provided by the kernel to us in the user State. They can be considered as some kernel library functions.
3. the main function of the operating system API is to completely display the functions of the operating system and provide them to applications. Based on the operating system, ability to interoperate with files, memory, clock, network, graphics, and various peripherals. In addition, the operating system API usually provides many tool functions, such as manipulating strings, various data types, and time and date. There is a direct relationship between API functions and system calls. An API function can be called by one system or multiple systems, it can also be called without any system at all.
4. The system call efficiency is not necessarily higher than the database function.