Question

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?

Was it helpful?

Solution 2

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).

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top