Linux learning articles (four) - process and kernel perspective detection system

 

 

Inspect the system from the perspective of process and kernel



      When completing many daily programming tasks, programmers are used to thinking about programming issues in a process-oiened way of thinking. However, when studying the various topics covered later in this book, it is necessary for readers to switch perspectives and look at problems from the perspective of the core. In order to highlight the differences between the two, the rest of the book will examine the system from the process and kernel perspectives respectively.

      A running system usually has multiple processes running in parallel. For processes, many events occur unexpectedly.

  • The executing process does not know when its CPU usage "expires", which process the system will schedule to use the CPU (and in what order), and when it will get the CPU again usage of.
  • The transmission of signals and the triggering of inter-process communication events are coordinated by the kernel, and may occur at any time for a process.
  • The process does not know where it is in RAM, that is to say whether a particular part of the process's memory space now resides in memory or is kept in swap space (a reserved area of ​​disk space that complements the computer's RAM) , the process itself is not aware of.
  • Processes also don't know where the files they access "live" on the disk drive, they just refer to them by name.
  • Processes operate in what can be described as "hollowed out"—processes cannot communicate directly with each other.
  • The process itself cannot create a new process, even if it "kills itself".
  • Finally, there is another point that the process cannot directly communicate with the input and output devices external to the computer.


      In contrast, the kernel is the center of the operating system. It knows everything about the system and is omnipotent, and facilitates the operation of all processes on the system.

  • Which process will take over the use of the CPU, when to "take over", and how long the "term" is, is up to the kernel.
  • Information about all running processes is contained in data structures maintained by the kernel.
  • As processes are created, state changes, or terminate, the kernel updates these data structures in a timely manner.
  • Low-level data structures maintained by the kernel translate file names used by programs into physical locations on disk.
  • In addition, the mapping relationship between the virtual memory of each process and the computer's physical memory and disk swap area is also a data structure maintained by the kernel. All communication between processes must be done through the communication mechanism provided by the kernel.
  • In response to requests from processes, the kernel creates new processes and terminates existing ones.
  • Finally, it is up to the kernel (specifically, device drivers) to perform all direct communication with input and output devices, exchanging information with user processes as needed.


      Wording such as "a process can create another process", "a process can create a pipe", "a process can write data to a file", and "call exit() to terminate a process" will appear throughout the remainder of this book. process". It is important to keep in mind that all of the above actions are centered and "mediated" by the kernel, and the above statement is just an acronym for "a process can ask the kernel to create another process", and so on.
 

 

---------------------------------------------《A Linux and UNIX System Programming Handbook》---------------------------------------------------

Guess you like

Origin blog.csdn.net/qq_41899773/article/details/103911057