Differences between Linux kernel programming and user application programming
Source: Internet
Author: User
Differences between Linux kernel programming and user application programming-Linux general technology-Linux programming and kernel information. The following is a detailed description. Before that, I was not clear about the differences between linux kernel programming and user application programming. Just a few linux module programming times over the past few days. I have asked some friends about the problems and checked some information, I felt that I had some experience in kernel programming and user application programming, and I wrote it down.
1. the biggest difference between Linux kernel programming and user application programming is that the former runs in the kernel state, while the latter runs in the user State, sometimes it takes less time to switch to the kernel mode through some system calls.
2. the header files imported by kernel programming are all in the include folder of the kernel source code. For example, in my debian linux 2.6 environment, the header files are under/usr/src/linux/include, the header files imported by user application programming are all under the include folder of the development environment header files, for example, under my environment:/usr/include. That is, all header files to be included cannot be used without the kernel source code include.
3. to query whether a function can be used in kernel programming, you can use http://lxr-itec.uni-klu.ac.at/linux-2.6.4/identcheck (this is for linux2.6 kernel and 2.4 kernel). If Defined as a function can be found, otherwise, it will not work.
4. A simple example: When using socket programming, you basically use the socket () function to create a socket descriptor during application programming. The header file of include is mainly , And These header files are not included in the kernel source code include and cannot be used, but the kernel programming has its own set. During kernel socket programming, you need to use sock_create () to obtain a socket struct. If you want to use the socket descriptor to operate the socket like your application, you can use sock_map_fd () to create a corresponding descriptor, in addition, you can use sockfd_lookup () to find the corresponding socket struct through the descriptor. In fact, the socket function kernel has sock_create () and sock_map_fd () first ().
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