1

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

1 Answer 1

0

You can send SIGTTIN or SIGTTOU with kill, like any other signal. You can trap them with trap (in sh), like any other (trappable) signal. But Ctrl+S and Ctrl+Q have nothing to do with signals. They're handled by the terminal, not by the application.

If you want your application to treat Ctrl+S as a “pause output” command, make sure the terminal does not capture these characters (stty -ixoff or the tcsetattr equivalent), and handle them like any other input.

2
  • "But Ctrl+s and Ctrl+Q have nothing to do with signals. They're handled by the terminal, not by the application." Is there a way to bind Ctrl+S and Ctrl+Q in zsh to do something like send a signal? That is why I originally added zsh tag. Afaik, keybindings are only supported for line editor, not when shell is in interactive mode. Commented Feb 2, 2023 at 2:23
  • @codepoet Zsh key bindings only have an effect on zsh. While an application is running in the foreground, zsh isn't receiving input. Commented Feb 2, 2023 at 11:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.