【发布时间】:2016-08-17 07:27:22
【问题描述】:
在我的操作系统上,默认情况下,ZSH 有 -tostop(或者是 tty?)。
这允许后台进程在有输出时输出到 shell。
因此:
> stty -tostop
> echo 'random' >/tmp/random
> cat /tmp/random &
[1] 7588
random
[1] + 7588 done cat /tmp/random
相应地:
> stty tostop
> echo 'random' >/tmp/random
> cat /tmp/random &
[1] 3888
[1] + 3888 suspended (tty output) cat /tmp/random
阅读文档并尝试了一下,我发现 ZSH 有 4 种类型的挂起进程(您可以使用 kill -$SIGNAL $PID ; jobs 看到这一点):
job state - signal that gives you job state
suspended - SIGTSTP
suspended (signal) - SIGSTOP
suspended (tty input) - SIGTTIN
suspended (tty output) - SIGTTOU
这意味着3888 进程正在接收SIGTTOU 信号。
这一切都说得通。
现在我的问题是,为什么less 不受stty tostop 或stty -tostop 的影响?
> stty tostop
> less /tmp/random &
[1] 6300
[1] + 6300 suspended (tty output) less --LONG-PROMPT --chop-long-lines /tmp/random
> stty -tostop
> less /tmp/random &
[1] 4808
[1] + 4808 suspended (tty output) less --LONG-PROMPT --chop-long-lines /tmp/random
正如您在这两种情况下看到的那样,less 总是在后台暂停。
现在,我知道了less -X,我也知道了终端模拟器的备用屏幕功能。 事实上,你可以用less -X 运行上面两个命令,它会导致同样的暂停。 即使-X 使它不使用备用屏幕,less 仍然得到suspended (tty output) !
我想知道的是less 总是被suspended (tty output) 暂停的实际机制,即使tostop 被切换,即使-X 也被切换。 shell 怎么能一直发送SIGTTOU 到less,除非有其他方式less 被挂起。
【问题讨论】:
-
备用屏幕与
less中的信号处理无关。
标签: terminal signals zsh terminal-emulator less-unix