tags:

views:

129

answers:

2

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?

+2  A: 

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.

Tyler McHenry
but I have -tostop on my tty set, so normal procs won't pause when writing stuff to the terminal. Is it generated when a backgrounded proc tries to change the line discipline of the tty?
jdizzle
I should say when normal *backgrounded* procs write to the terminal.
jdizzle
+1  A: 

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

jdizzle