process是OS邏輯排程執行的基本單位。為了管理process,OS會將process分組管理,**session和process group (PG)**就是process群組的單位。一個session可包含多個process group,一個process group可以包含多個process。session/PG有以下性質:
每個session/PG都會有一個leader,通常是該群集中第一個process
每個session/PG都會有一個id,由該群集中第一個process的PID決定
每個session可以配給一個terminal
一個session中,terminal會被attach到其中一個process group
被attach terminal的process group給名詞叫foreground process group
在shell中,foreground/backend process group可以用bg/fg/jobs指令管理切換。
Signal
訊號/信號是Unix、類Unix以及其他POSIX相容的作業系統中行程間通訊的一種有限制的方式
它是一種異步的通知機制,用來提醒行程一個事件已經發生
當一個訊號傳送給一個行程,作業系統中斷了行程正常的控制流程,此時,任何非原子操作都將被中斷。
SIGTERM
a generic signal used to cause program termination.
Unlike SIGKILL, this signal can be blocked, handled, and ignored.
It is the normal way to politely ask a program to terminate.
The shell command kill generates SIGTERM by default.
SIGINT (“program interrupt”)
is sent when the user types the INTR character (normally C-c).
SIGQUIT
similar to SIGINT, except that it’s controlled by a different key—the QUIT character, usually C-\
produces a core dump when it terminates the process, just like a program error signal.
You can think of this as a program error condition “detected” by the user.
Certain kinds of cleanups are best omitted in handling SIGQUIT.
For example, if the program creates temporary files, it should handle the other termination requests by deleting the temporary files.
But it is better for SIGQUIT not to delete them, so that the user can examine them in conjunction with the core dump.
SIGKILL
cause immediate program termination.
It cannot be handled or ignored, and is therefore always fatal.
It is also not possible to block this signal.
This signal is usually generated only by explicit request. Since it cannot be handled, you should generate it only as a last resort, after first trying a less drastic method such as C-c or SIGTERM. If a process does not respond to any other termination signals, sending it a SIGKILL signal will almost always cause it to go away.
In fact, if SIGKILL fails to terminate a process, that by itself constitutes an operating system bug which you should report.
The system will generate SIGKILL for a process itself under some unusual conditions where the program cannot possibly continue to run (even to run a signal handler).
SIGHUP (“hang-up”)
is used to report that the user’s terminal is disconnected, perhaps because a network or telephone connection was broken.
This signal is also used to report the termination of the controlling process on a terminal to jobs associated with that session
this termination effectively disconnects all processes in the session from the controlling terminal. For more information