From the description of signals (reference), it seems like SIGTTIN and SIGTTOU are sent to a process only if it is in background. Pressing Ctrl-s
does stop printing in terminal, if such flow control is enabled. So the question is, is it possible to actually pass SIGTTIN/SIGTTOU signals to a process currently in foreground and trap it?
As an example, save the following code in a file, chmod +x
and run it. Then press Ctrl-s
/Ctrl-q
. You would notice that Ctrl-s
does stop and Ctrl-q
does resume printing. But the file ./trap.log
file will be empty.
#!/usr/bin/env zsh
touch ./trap.log
trap 'echo TSTP >>./trap.log' TSTP
trap 'echo TTIN >>./trap.log' TTIN
trap 'echo TTOU >>./trap.log' TTOU
trap 'echo CONT >>./trap.log' CONT
for ((i=1;i>0;i=i+1)); do
printf "print $i\n"
sleep 1
done