📜  系统调用和库调用的区别

📅  最后修改于: 2021-09-12 11:09:22             🧑  作者: Mango

1.系统调用
计算机系统中有两种模式,一种是用户模式,另一种是内核模式。在计算机系统中,有不同类型的进程在计算机系统上运行。当用户运行应用程序时,它被称为处于用户模式或计算机处于用户模式。当对硬件资源有需求时,进程向内核发送请求以获得进程访问权,计算机进入内核态。这些请求是通过系统调用发送的。计算机经常在这两种模式之间切换。每当任务完成时,计算机就会从内核模式返回到用户模式。这种转换模式称为上下文切换。

2. 图书馆电话:
库调用是一种使用编程库中定义的特定函数的请求。库文件包含打包成一个文件以供使用的代码数据文件、目标文件。要进行库调用,应先导入库。库调用可能依赖于系统调用来完成任务。

系统调用和库调用的区别:

S.no        

SYSTEM CALL

LIBRARY CALL

1. A system call is a request made by the program to enter into kernel mode to access a process.. A library call is a request made by the program to access a library function defined in a programming library.
2. In kernel mode the programs are directly accessible to the memory and hardware resources. In user mode, the programs cannot directly accessible to the memory and hardware resources.
3. In system call, the mode is executed or switches from user mode to Kernel mode. In library call, the mode is executed in user mode only.
4. In system call the execution process speed is slower than the library call because there is a mode of transition called context switching. In library call the execution process speed is faster than the system call because there is no mode of context switching.
5. A system call is a function provided by the kernel to enter into the kernel mode to access the hardware resources. A Library call is a function provided by the programming library to perform a task.
6. System call are the entry points of the kernel, and therefore they are not linked to the program. Library functions are linked into your program.
7. A system call is not portable. A library call is portable.
8. System call have more privileges than library calls because it runs in a supervisory mode. Library call have less privileges than system calls because it is runs in a user mode only. 
9. System calls are provided by the system and are executed by the system kernel. Library calls included the ANSI C standard library. 
10. In system call all functions are a part of the kernel.  In library call all library functions are a part of the standard library file of programming languages. 
11. Whenever a program requires the memory or hardware resources, it directly sends a request to the kernel to get the process access by using a system call.

Whenever a programmer or a developer uses a specific library function, the programmer has to invoke or call the library function first by including a header file into his program. The preprocessor ( # ) directives helps to include header files. Some useful header files are :-

1. #include

2. #include

3. #include

12.

Examples of system calls are – 

1. fork() 

2. exec() 

Example of Library call are –

1. fopen()

2. fclose()

3. scanf()

4. printf()