OS 3 minutes a day practicing Cheats (5): System Calls

I see the point serial Cheats

Operating system service ports: System Calls

User process work in user mode, it is limited, many operations related to hardware are unable to perform, but they get the results they want, they can only request to work in the operating system kernel mode to help complete these operations, and operations The results to the user process.

System call (system call) is the operating system provides an interface to the user process requesting the operating system to do some privileged operations, that is, the user process to provide window services. In Linux you can man syscallssee all Linux system calls provided command.

Understand the system call is actually very simple, such as a program wants to read a.log file (for example head -n 1 a.log), you must first open the file before reading, but the process is user does not have permission to open the file, the user process can only send one open ( ) system call requesting the operating system to help open the file, the operating system to open the file will open after the results - the file descriptor to the user processes, user process through this file descriptor will be able to operate this file. Still further, the user process wants to read from the opened file row of data, the user process is not permission to read the file, only send a read () system call requesting the operating system to read this line data, operating system read this line will be able to take the data to the user process.

Not difficult to find, the system call open () and read () function is like. In fact, they are indeed function, but is rather special provided by the operating system, usually written in assembly language or doped some assembler code, and hardware because they want to interact.

For non-C program, in fact, the essence is still the same. CPython example, there are open () function, which is to be resealed C library function to open (). So, call in Python programs open () method to open the file, in fact, is to call the C library open () function, and through the open () library function to initiate a system call requesting the operating system to open the file, and the results handed over to Python programs.

Finally, the concept of interrupt described earlier, the main process after the system call initiated under the description:

  1. Initiate a system call, requesting the operating system to help perform certain operations, which results in soft interrupt;
  2. Soft interrupt lead into the kernel, CPU control to the operating system, the operating system interrupt, that perform the requested operation;
  3. Will return to the breakpoint continue down if all goes well, the operating system to complete the operation, it will return to user mode;
  4. A user process to fruition an operating system, and continue downward.

Guess you like

Origin www.cnblogs.com/f-ck-need-u/p/11653573.html