When I scp a file, I can stop it with ^Z and put it in the background. When it's in the background it stops printing its progress but the copying continues. If I foreground it again, it resumes printing. How does it know? SIGTTOU? does that happen on a standard ptty?
scp文件的时候,我可以停止^ Z和把它在后台。当它在后台时,它停止打印进程,但复制继续。如果我再次突出显示它,它将继续打印。它是如何知道的?SIGTTOU吗?这是在标准ptty上发生的吗?
2 个解决方案
#1
2
Yes, you got it. The process would trap or ignore SIGTTOU (and maybe SIGTTIN, depending on what it's doing), and then it would behave appropriately when receiving those signals. Linux does indeed send those signals on normal pseudo-terminals.
是的,你明白了。这个过程会捕获或忽略SIGTTOU(可能还有SIGTTIN,这取决于它在做什么),然后在接收到这些信号时,它就会表现出适当的行为。Linux确实在正常的伪终端上发送这些信号。
#2
1
A coworker of mine and I actually looked through the source and found the answer.
我和我的一位同事实际上查了一下资料来源,找到了答案。
Whenever scp is about to print output it runs tcgetpgrp on stdout. This will return the controlling process group of the terminal (assuming it is a terminal). It will only print out if process group controlling the terminal is the same as the process group of scp. Turns out no signalling required! (Though it does handle SIGWINCH to calculate the size of the progress line).
每当scp准备打印输出时,它都会在stdout上运行tcgetpgrp。这将返回终端的控制过程组(假设它是一个终端)。只有当控制终端的进程组与scp的进程组相同时,才会打印出来。结果证明不需要信号!(尽管它确实处理了SIGWINCH来计算进度条的大小)。
#1
2
Yes, you got it. The process would trap or ignore SIGTTOU (and maybe SIGTTIN, depending on what it's doing), and then it would behave appropriately when receiving those signals. Linux does indeed send those signals on normal pseudo-terminals.
是的,你明白了。这个过程会捕获或忽略SIGTTOU(可能还有SIGTTIN,这取决于它在做什么),然后在接收到这些信号时,它就会表现出适当的行为。Linux确实在正常的伪终端上发送这些信号。
#2
1
A coworker of mine and I actually looked through the source and found the answer.
我和我的一位同事实际上查了一下资料来源,找到了答案。
Whenever scp is about to print output it runs tcgetpgrp on stdout. This will return the controlling process group of the terminal (assuming it is a terminal). It will only print out if process group controlling the terminal is the same as the process group of scp. Turns out no signalling required! (Though it does handle SIGWINCH to calculate the size of the progress line).
每当scp准备打印输出时,它都会在stdout上运行tcgetpgrp。这将返回终端的控制过程组(假设它是一个终端)。只有当控制终端的进程组与scp的进程组相同时,才会打印出来。结果证明不需要信号!(尽管它确实处理了SIGWINCH来计算进度条的大小)。