Meanings and usage of Linux man manual chapters

Source: Internet
Author: User

Linux man is very powerful. This manual is divided into multiple sections. When using man, you can specify different sections for browsing. The meaning of each section is as follows:
1-Commands
2-system CILS
3-library CILS
4-special files
5-file formats and convertions
6-games for Linux
7-macro packages and conventions
8-system management commands
9-others
To explain,
1 is a common command
2 is a system call, such as open and write (through this, at least we can easily find the header file to be added to call this function)
3 is a library function, such as printf and fread
4 is a special file, that is, various device files under/dev.
5 indicates the file format. For example, passwd indicates the meaning of each field in the file.
6 is reserved for games, defined by each game
7. Some variables are attached. For example, global variables such as environ are described here.
8 is a command used for system management. These commands can only be used by root, such as ifconfig
If you want to specify a section, add a number to the end of man. For example:
MAN 1 ls
MAN 3 printf
And so on.
For existing commands such as open and kill and system calls, man open displays open (1), that is, starting from the front section, if you want to view the open system call, you need man 2 open

About library functions and system calls

Library functions are high-level and fully run in the user space, providing programmers with more convenient interfaces for calling systems that actually complete real transactions behind the scenes. System calls run in kernel mode and are provided by the kernel itself. Standard C library functionsprintf()
It can be seen as a general output statement, but what it actually does is to convert the data into a formatted string and call the system callwrite()
Output these strings.

Do you want to have a look?printf() What system calls are actually used? This is easy to compile the following code.

 

#i nclude <stdio.h>int main(void){ printf("hello"); return 0; }

Use commandsGcc-wall-O hello. cCompile. Use commandsStrace hello
Trace the executable file. Are you surprised? Each line corresponds to a system call. Strace is a very useful program that tells you which system calls the program uses and the parameters and return values of these system calls. This is a very valuable tool for viewing what the program is doing. At the end of the output, you should see such a line
write(1, "hello", 5hello) . This is what we are looking. Hidden in maskprintf()
. Since most people use library functions to operate on file I/O (such as fopen, fputs, and fclose ). You can view the second part of man's instructions using commandsMAN 2 Write. The second part of man's description specifically introduces system calls (suchkill()
Andread() ). The third part of man's description specifically introduces library functions that you may be more familiar with (suchcosh()
Andrandom() ).

You can even write code to overwrite system calls, as we will soon do. Hackers often do this to install backdoors or Trojans for the system. But you can use it to do something more useful, like making the kernel output"
Tee hee, that tickles!.

 

 

Summary:

From the perspective of functions completed by the program, the functions provided by the function library usually do not require the services of the operating system, and the functions are executed in the user space, unless the function involves I/O operations, etc, generally, it is not switched to the core state. System calling requires the operating system to provide processes and services for users, usually involving hardware resources and sensitive software resources of the system.

Functions of the function library, especially those related to input and output, must be called in Linux. Therefore, we can regard the function of the function library as an intermediate layer between the Application Designer and the system calling program. Through this middle layer, we can use the same interface to safely call the system call. In this way, the programmer can write the code once to implement completely different system calls by using the backlog among Linux systems of different versions. As for how to implement compatibility with different system calls, it is a concern of function library developers.

From the perspective of program execution efficiency, most of the execution efficiency of system calls is higher than that of functions, especially the input and output functions. When the amount of data processed is relatively small, the function execution efficiency of the function library may be better, because the function library stores the data to be processed in the buffer first, and when the buffer is full, write or read the data again. In this way, the processing efficiency of a small amount of data is relatively high, but when the system is called, because the user process enters the system core mode from the user mode, many additional tasks are involved in switching, these operations are called context switches. This extra work affects the system's execution efficiency. However, when the amount of data to be processed is large, for example, when the amount of input and output data exceeds the limit defined by the file system, system calls can achieve high efficiency.

From the perspective of program portability, the standard Standby function library (ansi c) in C language is highly portable compared to system calls. In different system environments, as long as few changes are made, there is usually no need to modify them.

Http://samuschen.iteye.com/blog/700944

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.