The "preface" is explained in the blog post:
This article will introduce a personal tone of the Linux Man command in the meaning of the number (including system calls and library function interpretation), at the current point in time "June 13, 2017 " under the grasp of the technical level is limited, there may be a lot of knowledge understanding is not deep or comprehensive, We would like to point out the issue of common communication, in the follow-up work and learning, such as found in this article and the actual situation deviation, will improve the content of this blog post.
This article refers to a reference link:
1, http://www.cnblogs.com/chao1118/p/3715523.html
2, http://blog.csdn.net/high_high/article/details/7200053
3, http://www.cnblogs.com/yudao/p/4369982.html
4, http://blog.csdn.net/skyflying2012/article/details/10044343 "This article is good"
Body:
The man in the Linux man is the abbreviation for manual, which is used to view the various reference manuals that are brought in the system.
Command format: Man [n] Command
The man command has 9 option numbers, which correspond to the following relationships:
1 executable programs or shell commands
2 System calls (functions provided by the kernel)
3 Library Calls (functions Wiroutinesthin program libraries)
4 special files (usually found In/dev)
5 File formats and conventions eg/etc/passwd
6 games
7 miscellaneous (including macro packages and conventions), e.g. man (7), Groff (7)
8 System Administration commands (usually only for root)
9 Kernel routines [Non Standard]
English literal translation:
1.executable program or shell command
2.system Calls(The kernel can call functions, run in nuclear mentality, kernel space, the system core can directly call functions and tools, etc., through this, it can be easily found to call a function, need to add what header file, such as the Open,write function)
3.Library Functions (Run in user-state, user-space, some common functions and libraries, mostly C libraries, such as Print,fread.
4, special equipment (usually a/dev under a variety of equipment, such as hard disk equipment, CD-ROM, etc.)
5.file Format(Describe the meaning of each field in this file, such as/etc/passwd)
6, the game (reserved for the game use, by the individual game definition)
7, miscellaneous, such as Linux file system, network protocol, variable description, etc.
8.System Plumbing Command(Commands that only administrators can use, such as ifconfig,reboot, etc.)
9. Files related to kernel kernel
Example:
suse11sp3-1:~ # man passwd
Man:find All matching manual pages
* PASSWD (1)
passwd (5)
passwd (1SSL)
Man:what manual page do you want?
Mans:
here if we
Enter 1, which means we want to see information about the/USR/BIN/PASSWD command.
Enter 5, which means we want to see information about/etc/passwd this file.
Enter 1ssl, which means we want to see the information about the OpenSSL passwd command.
what are system calls and library functions?
first, the system calls
System call is a function provided by the operating system kernel, in the kernel state operation (kernel mode), is the operating system for the user to provide some of the interface, belonging to the lower of the function, although low, but who can not leave them, because left them there is no way to deal with the kernel, There's no way to deal with the kernel.
For example, the standard C library function printf () can be seen as a generic output statement, but what it actually does is convert the data into a conforming string and call the system to call write () to output the strings. I want printf ("hello,world! "), which is actually called write (), and this write () is the system-provided interface function
So what is the meaning of the system call?
1. The system call frees us from the underlying hardware programming.
If you think about it, it's tiring to write a program that also requires you to implement code that prints strings on the screen.
2. Improve system security
System call is the kernel code, the kernel code can access all the address space on the system, and we execute the code is the user space code, the user space code in the operation of the system is limited, (as a novice programmer, if the system does not limit the code you write, in case the system jumped it). Therefore, another function of the system call is to maintain the security of the system, you need to directly call me this interface on the line, do not write your own.
3, System call also has a function is to facilitate the portability of the program.
In short, you put the system call as a system underlying interface, when you need to use it, call it on the line, both convenient and secure.
Second, the library function
Library functions are high-level, a layer of packaging on system calls, running in user mode, providing programmers with a more convenient interface to invoke real-world system calls that do real-world transactions behind the scenes. You can actually think of the library function as another encapsulation of the system call. For example, the library function is equivalent to Contractor, the system call is a worker, we can find their own workers sub-task, but generally the task to contractor, contractor again to the workers sub-task.
So what is the meaning of the library function?
1, improve the execution efficiency of the procedure.
System call as the kernel provided to our interface, its execution efficiency is more efficient and streamlined. But sometimes we need to do more complex processing of the information we get, so what if we wrap this process up as a function and then provide it to the programmer, isn't it easier to program? Therefore, a library function may have a system call, there may be several system calls, of course, there may be no system calls, such as some operations do not need to involve the functionality of the kernel.
2, improve the portability of the program
From the point of view of the portability of the program, the standard Library of C (ANSI c) has a high portability relative to the system call, and in different system environments, as long as there is little modification, it is usually not necessary to modify it.
So while eventually all of the work is done by system calls, it's more common to call library functions for several reasons:
1, the library function provides abstraction, abstraction is a good thing, can let us focus more attention on the problem to solve the core.
2, library functions to provide us with a more user-friendly interface, so it is more convenient to call.
3, call library functions more secure, memory management do not worry too much.
4, call the library function more efficient, the program runs faster. Although library functions ultimately call system functions, library functions call system functions better than we do in a way. Because the system call is a kernel-state function, each call to the kernel from the user state to the kernel state, the main thing is the library function inside the cache, can reduce the number of system calls, the same 100 output, written system call is naked 100 system calls, rather slow , and a library function may be saved by the internal cache to invoke the system call output once, oh, efficiency is of course fast. However, in some special cases only system calls can be used, such as writing drivers, using special input and output controls, and so on.
Add:
Library functions can be packaged not only on the basis of system invocation, but also on the basis of other library functions, providing more advanced abstraction and more powerful functions. For example, Ogre to OpenGL packaging, QT Xlib packaging, similar to from the boss to the Secretary to the department head to contractor to the worker process, of course, I we are mister, as long as we are happy, not only call the Secretary (good evil ah ...) ), directly call the supervisor, contractor, even when the workers themselves can, write a system call, and then recompile the kernel, and then call their own written system calls, you can refer to the link below.
Write your own system call: Jump Link: http://tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/#AEN27
Summary:
System calls are designed to make it easier for applications to use the operating system's interfaces, and library functions are designed to facilitate people writing applications.
Finally, we introduce two tools, Strace and Ltrace.
Strace See what system calls our executables call
Ltrace See what library functions the executable has called, friends who like reverse engineering must like it.
The usage is simple, just follow the executable path directly behind the command.
End:
Thank you for reading, I wish you a rewarding day, thank you!
This article is from the "Breeze Month Blog" blog, please be sure to keep this source http://watchmen.blog.51cto.com/6091957/1935103
Number meanings in the Linux-man command (including system call and library function explanation)