Difference between system call and library function __ function

Source: Internet
Author: User

The so-called system call is the operating system provided to the application of a series of interfaces. Under Linux There are several types: Process control (such as: fork), file system control (such as: Write), system control (such as: reboot), memory management (such as: GetPageSize get the page size-not seen ...) , network management (getdomainname domain name), socket control (such as the above mentioned socket, bind, etc.), user management (Getuid get user identification number), interprocess communication (pipe create pipelines) and so on. When an application invokes a system call, the process of the program is switched from user state to kernel state. System calls also include header files.

Library functions, as the name suggests, put functions in the library. It's someone who makes up a few commonly used functions and puts them in a file for others to use. When someone else uses it, add the file name of the #include<> to the inside.

The so-called library functions, can be divided into two categories: one is the C language standard in the library function, the second is compiler-specific library functions.

Some library functions end up with system calls, such as printf (), which will end up with write () in the system call. Because the application may involve some IO read/write, memory control, network management and other operations, the user may write a program by writing a library function call (such as: Want to print statements, write a printf ()), these library functions to enable system calls. So, some library function is a window of system call.

Difference:

1. The cross-platform nature of the library functions is good, as printf () can be used under Windows and Linux. And the system call is almost nothing cross-platform (this refers to a large platform, such as Windows, Linux, Apple operating system, etc., rather than Linux, such as a certain version and a certain version).

2. Because the system call is running the kernel state, so its execution speed is generally faster than the library function, the library function finally to call to the system. But the library function sometimes does some lifting of high-performance processing, such as printf (), it will wait until the buffer full write again, this saves the program from user state to the kernel of the number of times, thus saving time.

3. During the debugging process, you can use the Strace tracking system call to Ltrace Trace library function calls.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.