Summarize Processes, Process Groups, Jobs, Sessions

This article focuses on several basic concepts of the relationship between processes. Described from the following aspects:

  • process
  • process group
  • Operation
  • conversation

process:

A process is a core concept of an operating system. Each process has a process control block (PCB) in the kernel to maintain process information, so that a program that cannot run independently in a multiprogramming environment can become a basic unit that can run independently or a process that other processes execute concurrently .

The process control block of the Linux kernel is the task_struct structure. task_struct is a data structure of the Linux kernel. It will be loaded into RAM and contain process information.

  • The task_steuct structure contains the following:

write picture description here

  • The process with process ID 0 is usually the scheduler process and is often referred to as the "swapper".

  • The process whose process ID is 1 is the init process, which is called by the kernel at the end of the system bootstrap process. The program file for this process is /sbin/init. This process is responsible for starting a Unix system after bootstrapping the kernel. init typically reads system-dependent initialization files (/etc/rc* or /etc/inittab, and files in /etc/init.d/) and boots the system into a certain state. The init process will not be terminated, and all processes generated after the system is started are derived from the init process.

  • Task_steuct structure organization form:
    write picture description here

  • Extension:

Through the above introduction, understand the related concepts of the process.
In fact, in addition to having a process ID (pid), each process also belongs to a process group.
A process group is a collection of one or more processes, each with a unique process group ID (pgid).

write picture description here


Process group:

Definition: A process group is a collection of one or more processes. Reason for
introduction : It is used to control the distribution of signals to multiple processes. When sent to a process group, the signal will occur to each process in the process group.

In addition to a process id, a process also belongs to a process group. A process group is a collection of one or more processes. Usually, they are associated with the same job and can accept various signals from the same terminal. Each process group has a unique process group id. Each process group can have a group leader i process. The identity of the group leader process is that its process group id is equal to its process id. The group leader process can create a process group, create the processes in the group, and then terminate. As long as a process exists in a process group, the process group exists, regardless of whether its leader process terminates.

  • In layman
    's terms, the school will manage students in different classes. If a student is the first to sign up, then his student number is No. 1, and his class is also a class. He is the monitor of this class. The student number is No. 2, No. 3, No. 4...,
    then the No. 1 student is the group leader process, and this class 1 is the process group. Their identifiers are the same, and the subsequent processes belong to this process group.
    If one day the monitor drops out and he doesn't go to school, then the student number 1 no longer exists, but class 1 is still there, and the rest of the students are still in this class.
    If the remaining students also drop out one by one, until there is only one person left in the class, then the class still exists.
    If all the students in the class are gone, and there is no one, then the class will cease to exist.

Based on the above understanding, the following points are summarized:

  • The process group leader id is the same as the process group id.
  • The process group leader can be terminated, but the process group will not disappear.
  • As long as there is one more process in the process group, the process group exists.
  • When all processes in the process group are terminated, the process group ceases to exist.

write picture description here


Operation:

Shell can perform job control, that is, it can run a foreground job and any number of background jobs, and each job can be one or more processes.

The difference between a job and a process group:
If a process in the job creates a child process, the child process does not belong to the job. Once the job is finished, the shell brings itself to the foreground, and if the original foreground process still exists (if the child process has not terminated), it automatically becomes the background process group.

  • job control

jobs: view the current job
fg: put the background job back to the foreground
bg: put the foreground job in the background and run

Session:

Definition: A Session is a collection of one or more process groups. Typically, a session begins when the user logs in and ends when the user logs out, and all processes that the user runs during this period belong to this session.

A session is a collection of one or more process groups. A session can have one controlling terminal. This is usually the terminal device or pseudo terminal device to which it is logged. The session leader process that establishes the connection with the controlling terminal is called the controlling process. Several process groups in a session can be divided into a foreground process group and one or more background process groups. So a session should include the controlling terminal, a foreground process group and any background process group.

write picture description here

  • You can view the session id: SID in the following figure:
    write picture description here

  • Summary: To
    sort out the concepts we have learned before, we have roughly drawn the following picture:
    write picture description here

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325732441&siteId=291194637