Linux C application programming study notes - (1) application programming concepts

"[Punctuality Atom] I.MX6U Embedded Linux C Application Programming Guide" study notes

system call

The set composed of all system calls provided by the operating system implementation is a program interface or an application programming interface (API). It is the interface between the application and the system.

--Baidu Encyclopedia

Through system calls, a Linux application can ask the kernel to do something on its own behalf, such as manipulate a disk file (open, read, or write).

The relationship between applications, system calls and the kernel can be represented by the following diagram.

Image source: "[Punctuality Atom] I.MX6U Embedded Linux C Application Programming Guide"

insert image description here

In Linux application programming (system programming), system APIs (such as open, write, read, close, etc.) are called in the application to complete the functions and logic of the application.

The Linux operating system has two states: kernel state and user state. The application runs in the user state, but the application can use the system API to complete some tasks running in the kernel state.

Library Functions

In addition to using system calls to interact with the kernel, applications can also use library functions.

The library function here refers to the C language library function. When we first came into contact with the C language, we began to deal with the library functions, such as printf(), scanf(), strlen()and so on. In Linux systems, library functions are usually stored in the /lib directory in the form of dynamic library files (.so). C library functions are built on system calls, that is, library functions contain system calls, but not all library functions use system calls (such as some string processing functions strlen(), memset()etc.), and many library functions are system calls Encapsulation, for example, the bottom layer of the fwrite()function is write()to complete the file write operation through system calls.

The difference between library functions and system calls:
library functions belong to the application layer, while system calls are the programming interface provided by the kernel to the application layer and are part of the system kernel;
⚫ Library functions run in user space, and system calls are called by user space ( User mode) into the kernel space (kernel mode);
⚫ Library functions are usually cached, while system calls are not cached, so in terms of performance and efficiency, library functions are usually better than system calls;
⚫ Portability: Compared with system calls, library functions have better portability. Usually, for different operating systems, the system calls provided by the kernel to the application layer are often different, such as system call definitions, functions, parameter lists, return values, etc. are often different; and for the C language library functions, since many operating systems have implemented the C language library, the interface definition of the C language library is almost the same between different operating systems, so the library functions are different in different operating systems. Better portability between operating systems than system calls.

——"[Punctual Atom] I.MX6U Embedded Linux C Application Programming Guide"

Application programming is simply: developing Linux applications, by calling the system calls provided by the kernel or using C library functions to develop applications with corresponding functions.

Standard C language library

Under the Linux system, the C language library used is the GNU C language function library (also called glibc, whose website is http://www.gnu.org/software/libc/ ), as the standard C language function library under Linux .

The following is the information of the GNU C language library functions of Ubuntu 16.04 in my computer, which exists in the system as a dynamic library.

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43772810/article/details/125570991