In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what is the concept of system call in linux". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the concept of system call in linux".
In linux, system call refers to a set of special interfaces provided by the operating system to the user program call, according to which the user program can get the service of the operating system kernel; the system call stipulates that the user process falls into the specific position of the kernel, or plans the path for the user to access the kernel, and can only enter the kernel from a fixed position.
The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
What is a system call in linux
1. What is a system call
System call refers to a set of special interfaces provided by the operating system to the user program, according to which the user program can obtain the service of the operating system kernel. It stipulates that the user process is trapped in the specific location of the kernel, or plans the path for the user to access the kernel, and can only enter the kernel from a fixed location.
System call of 2.linux
For modern operating systems, system call is a common means of communication between user space and kernel, and linux is no exception. According to the functional area, linux system call is roughly divided into process control, file access, system control, storage management, network management, process communication and so on. For more information, you can view the manpage description through the man 2 syscalls command.
The system call only submits the request to the kernel through the soft interrupt mechanism and enters the corresponding service of the system call. The user programming interface provided by linux follows the POSIX standard, which not only defines some standard C functions, but also provides a set of encapsulation routines to encapsulate system calls for user programming. However, encapsulation is not necessary, and if you are willing to call it directly, the linux kernel also provides a syscall () function to implement the call. Use the following example to understand the difference between C library calls and direct calls.
/ * file: demo.c** author: eric.xu** date: 2016-02-25*/#include # include int main (void) {long id1, id2; / * system call no 20, _ NR_getpid equal to SYS_getpid * / id1 = syscall (_ _ NR_getpid); printf ("sys_call getpid% ldn", id1); / * libc getpid * / id2 = getpid () Printf ("libc getpid ldn", id2); return 0;}
Compile and run, you can see that the two results are the same.
Sys_call getpid 2899libc getpid 2899
Implementation of 3.linux system call
When a process in user mode calls a system call, CPU switches to kernel state and starts executing kernel functions. Because each system call in the kernel has a unique label, the user-mode call must pass a parameter of the system call number to determine the specific system call function. All system call functions are integers. In the kernel, integers and 0 indicate the successful completion of the system call, while negative numbers indicate an error condition, and this error value is stored in the errno variable and returned to the application as an error code.
Linux system calls are implemented using soft interrupts, calling the int $0x80 assembly instruction in x86 architecture, which produces an exception with a vector of 128. In the arm architecture, enter the kernel space through the SWI instruction, take a look at the format of this instruction:
SWI {cond} immed24; where immed24 represents 24-digit immediate numbers
The SWI exception interrupt handler needs to obtain 24-bit immediate numbers by reading SWI instructions that cause software interruptions. The basic step is to access the SPSR register to determine whether the instruction is an ARM instruction or a Thumb instruction after the SWI exception is generated, then get the entire instruction address by accessing the LR register, and then get the instruction to get the lowest 24-bit immediate number.
Thank you for your reading, the above is the content of "what is the concept of system call in linux". After the study of this article, I believe you have a deeper understanding of what the concept of system call in linux is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.