码迷,mamicode.com
首页 > 系统相关 > 详细

后台进程读写终端的限制,SIGTTIN 信号, SIGTTOU 信号, tostop 属性

时间:2019-04-25 18:59:58      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:locking   RoCE   always   similar   code   ignore   sleep   AMM   processes   

Processes in the foreground job of a controlling terminal have unrestricted access to that terminal; background proesses do not. This section describes in more detail what happens when a process in a background job tries to access its controlling terminal.

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 (unless they handle the signal and don‘t stop themselves). However, if the reading process is ignoring or blocking this signal, then read fails with an EIO error instead.

Similarly, 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. However, the behavior is modified by the TOSTOP bit of the local modes flags (see section Local Modes). If this bit is not set (which is the default), then writing to the controlling terminal is always permitted without sending a signal. Writing is also permitted if the SIGTTOU signal is being ignored or blocked by the writing process.

Most other terminal operations that a program can do are treated as reading or as writing. (The description of each operation should say which.)

TOSTOP 控制后台任务是否能写终端,

stty tostop; (sleep 5; echo hello, world) &

tostop 被设置,任务试图写终端时,SIGTTOU 信号发送给该进程,进程停止。需手动 kill.

stty -tostop; (sleep 5; echo hello, world) &

取消 tostop,后台任务可以发送 hello, world 到终端。

$ stty -a
speed 38400 baud; rows 51; columns 151; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;
werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

可以看到 ubuntu 16.04 的默认设置是 -tostop.

参考资料

后台进程读写终端的限制,SIGTTIN 信号, SIGTTOU 信号, tostop 属性

标签:locking   RoCE   always   similar   code   ignore   sleep   AMM   processes   

原文地址:https://www.cnblogs.com/armme/p/10770225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!