The concept of a session linux, process, process group, etc.

1. Some abbreviations

PID = process ID (generated by the kernel algorithm based on the delay reuse)
PPID = parent process ID (can only be modified by the kernel)
PGID = process group ID (child process, the parent process can be modified)
SID = Session ID (the process itself can be modified, with limitations, see below)
TPGID = controlling terminal process group ID (modified by the control terminal indicates the current foreground process group)

2. The relationship between the process before the process group, session

Overall relationship:

Processes belonging to a process group, process group belongs to a session, the session may or may not have control terminal

 

 

Collection of one or more processes, process group belongs to a session. fork () does not change the process group ID.

Process Group Leader:
equal PID and PGID process. Group leader can change the process group ID of the child process, it is transferred to another process group.
For example, a shell process (hereinafter bash are an example), when using a pipeline, such as echo "hello" | cat, bash to all processes within the process ID of the first command for the pipeline is provided a process group ID. At this time, echo and process group ID cat are set to the process ID echo.
Foreground process group
process process the process group of the terminal device can read and write operations of the group.
Login shell (eg bash) by calling tcsetpgrp () function to set the foreground process group, the function (file descriptor) associated with fd terminal device with the specified process group. Become the foreground process group of its TPGID = PGID, they can often be judged by comparing before and after the process group.
Background process group
in a session, all processes in the foreground process group except the group, the first session process. The process group process can write to the terminal device, but when trying to read the terminal device, will receive SIGTTIN signal and stop. Login shell can issue a message on the terminal provided according to [1] a process to notify a user terminal desires to read.
Foreground process group ID can only have one, and the background process group at the same time there can be multiple. PGID ≠ TPGID background process group.
Head of the process:
  head of the process identity: its process group ID == its process ID of the
  head of the process can create a group process, the process of creating the process group, and then terminate
  as long as process group in the presence of a process, process group exists , has nothing to do with whether the head of the process to terminate
  the process group survival: the process of creating a process to the last group to leave (termination or transfer to another process group)
to establish a new session: setsid () function is
  the head of the calling process is a process, an error is returned
    First calls fork, the parent terminates, the child process calls
  the calling process is not the head of the process, create a new session
    • The process becomes a new session the first process (the session header)
    • The process to become head of the process a new process group.
    • The process does not have control terminal, if before, it will be interrupted
head of the process can not become a new session the first process, the new process will become the first session head of the process ...

3. zombie processes and orphaned
zombie process: first, the parent process terminates, the parent process but not be dealing with the aftermath (for information terminator process, it still release some resources). The only way to eliminate the zombie process is to terminate the parent process.
Orphan processes: the parent process of the process prior to their termination. It features PPID = 1 (ID init process). An orphan process can be self-made orphan process group.
Orphan process group:
the definition of a
parent of each member of the group is either a member of the group, or it is not a member of the group belongs session
define 2
conditions are not orphans process group is that the group has a process whose another parent group belonging to the same session.
In other words, the parent process terminates the process can make the composition of orphans process (thanks to friends of "hello" correction). The parent process is usually head of the process of this process group, because only its parent group outside of this process, but other processes (child processes head of) the parent process ID is the head of the process of
----- -----------
Disclaimer: this article is CSDN blogger "soup blog" in the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/tangli555/article/details/52027377

Guess you like

Origin www.cnblogs.com/cangqinglang/p/12110742.html