Linux system invocation and user programming Interface (API) learning

Source: Internet
Author: User
Tags file system

Linux system calls

System call refers to a set of "special" interfaces that the operating system provides to a user program, which can be used by the user program to obtain the services provided by the operating system kernel.

Why can't a user program directly access the services provided by the system kernel? This is because in Linux, in order to better protect the kernel space, the operating space of the program is divided into user space and kernel space (that is, often called user state and kernel state), they run at different levels, logically separated from each other. Therefore, user processes typically do not allow access to kernel data or kernel functions, they can only manipulate user data in user space and invoke user-space functions.

However, in some cases, the process of user space needs to obtain a certain system services (invoke kernel space program), then the operating system must use the system to provide the user's "special interface" ——— system calls to specify the user process into the kernel space specific location. When making the system call, the program running space needs to enter the kernel space from the user space, the processing completes then returns the user space.

Linux system calls are streamlined (only about 250), and it inherits the most basic and useful parts of UNIX system calls. According to the functional logic, these system calls can be divided into process control, interprocess communication, file system control, storage management, network management, socket control, user management and other categories.

User programming Interface (API)

The system call mentioned earlier does not interact directly with the programmer, it is simply an interface that submits a request to the kernel through a soft interrupt mechanism to obtain the kernel service. In practice, programmers often invoke user programming interfaces (APIs).

For example, the API function for creating a process fork () function corresponds to a sys_fork () system call to kernel space, but not all functions correspond to one system call. Sometimes, an API function requires several system calls to work together to complete functions, and even some API functions do not need to invoke the corresponding system call (so it does not perform the service provided by the kernel).

System commands

The system command is a layer higher than the API, it is actually an executable program, its internal reference user programming interface (API) to implement the corresponding functions, the relationship between them is as follows Figure 1:

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.