注册 登录
编程论坛 Linux系统管理

写Bash时,Job Control 的一点笔记

madfrogme 发布于 2012-08-03 23:09, 712 次点击
The processes belonging to a single command are called a process group or job.

Typing C-c sends the signal SIGINT to terminate all the processes in the foreground process group.

When a process is created, it becomes a member of the same process group and session as its parent process. You can put it in another process group using the setpgid function, provided the process group belongs to the same session.

The only way to put a process in a different session is to make it the initial process of a new session, or a session leader, using the setsid function.

The shell must cooperate with the terminal driver using the protocol to control which job can use the terminal at any time.

The shell can give unlimited access to the controlling terminal to only one process group(foreground job) at a time.

The user can stop a foreground job by typing the SUSP character and a program can stop any job by sending it a SIGSTOP signal.

Not all operating systems support job control, you can use the _POSIX_JOB_CONTROL macro to test at compile-time whether the system supports job control.

When a process in a background job tries to read from its controlling terminal, the process group is usually sent a SIGTTIN signal. This normally causes all of the processes in that group to stop. However, if the reading process is ignoring or blocking this signal, then read fails with an EIO error instead.

When a process in a background job tries to write to its controlling terminal, the default behavior is to send a SIGTTOU signal to the process group.

When a controlling process terminates, its terminal becomes free and a new session can be established on it.

When a process group becomes an orphan, its processes are sent a SIGHUP signal. Ordinarily, this causes the processes to terminate.
1 回复
#2
薛天佑2013-01-16 10:47
哈哈
1