linux-process, Process group, job, session, control end-of-day solution

Source: Internet
Author: User

First, the process

Traditionally, applications, servers, and other programs running under the UNIX operating system are called processes, and Linux inherits the concepts from UNIX processes. It must be understood that the program refers to a static entity stored on a storage device (such as a disk) that contains executable machine instructions (binary code) and data, whereas a process can be thought of as a collection of dynamic, runnable instructions and data that has been loaded into memory by the OS, and is a dynamic entity that is running. The set of instructions and data referred to here can be understood as the. Text. Data segment in the ELF file format on Linux.

Ii. Group of processes

  each process, in addition to a process ID, belongs to a process group , and what is a process group?

As the name implies, a process group is a collection of one or more processes. These processes are not isolated, they are either parent-child, sibling, or functionally related. each process has a parent process, and all processes are rooted in the init process, forming a tree structure .

  So why is there a process group in Linux? In fact, the process group is provided to facilitate the management of the process. Assuming that you want to complete a task, you need to concurrently 100 processes at a time. When the user is for some reason to terminate the task, if there is no process group, it is necessary to manually kill each of the 100 processes, and must be strictly in accordance with the process of parent-child sibling relationship order, otherwise it will disrupt the process tree. With the process group, the 100 processes can be set to a process group with 1 group Numbers (PGRP), and a process is selected as the leader (usually the highest of "generational"), usually the ID of the process group. You can now close these 100 processes by killing the entire process group, and it is strictly ordered. The leader process can create a process group, create a process in that 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 .

   A process must belong to a process group, or only to one process group .  A process group can contain multiple processes. The life cycle of a process group starts with the creation, where all processes terminate or leave the group.

  In the kernel, the SYS_GETPGRP () system call is used to obtain the process group number of the current process, and sys_setpgid (int pid, int pgid) calls the process group number Pgid used to set the top-process PID.

Third, the operation

The shell is not a process but a job or a process group that controls the front and back of the table. A foreground job can consist of multiple processes, one background can be composed of multiple processes,and the shell can run a foreground job and any number of background jobs , which is called job control.

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

Iv. Sessions

  Look at the conversation again. Since Linux is a multi-user multi-tasking time-sharing system, it is necessary to support multiple users using one operating system simultaneously. A session is formed when a user logs on to the system once. A session can contain multiple process groups, but only one foreground process group . each session has a session leader (leader), which is the process that creates the session. the sys_setsid () call can create a session. It is important to note that a new session can be created only if the current process is not the leader of the process group . After calling Setsid, the process becomes the leader of the new session.

A session can have a control terminal. This is usually the terminal device (in the case of terminal landing) or the pseudo terminal device (in the case of network Landing). the first process of establishing a session connected to a control terminal is called the control process . Several process groups in a session can be divided into a foreground process group and one or more background process groups. Therefore , a session should include the control process (session first process), a foreground process group, and any background process group .

  One logon to form a session

  A session can contain multiple process groups, but only one foreground process group

V. Control terminal

After the lead process of the session opens a terminal, the terminal becomes the control terminal of the session (Svr4/linux)

The session lead process that establishes the connection to the control terminal is called the control process (session leader)

A session can have only one control terminal

The inputs and signals generated on the control terminal are sent to all processes in the foreground process Group of the session

When a connection on the terminal disconnects (such as a network disconnection or Modem disconnection), the pending signal is sent to the control process (session leader)

  Each process is a member of a process group, and each process group is a member of a session . In general, when a user logs on at a terminal, a new session begins . The process group is identified by the lead process in the group, and the process identifier of the lead process is the group identifier of the process group. Similarly, each session should have a lead process .

  Processes in the same session are connected through the session's lead process and a terminal, which acts as the control terminal for this session. A session can have only one control terminal, and a control terminal can only control one session. By controlling the terminal, the user can send keyboard signals to processes in the session controlled by the control terminal.

There can be only one foreground process group in the same session, the process that belongs to the foreground process group can get input from the control terminal, and the other processes are background processes and may belong to different background process groups.

When we open multiple terminal windows, we actually create multiple terminal sessions. each session will have its own foreground work and background work .

linux-process, Process group, job, session, control end-of-day solution

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.