Quantcast
Channel: User Kamil Maciorowski - Super User
Viewing all articles
Browse latest Browse all 656

Answer by Kamil Maciorowski for How to bring a job to foreground and then disable job control in bash?

$
0
0

Basic solution

I wish to disable the Ctrl+Z shortcut from suspending the process.

For this you don't need to disable job control. Tell the terminal driver not to send SIGTSTP upon Ctrl+Z:

stty susp ''

If you have already started the process, press Ctrl+Z, run stty susp '' (from now on Ctrl+Z will not be special), then run fg.

To restore the usual meaning of Ctrl+Z:

stty susp ^Z

For convenience you can compact these to a single line. Just after Ctrl+Z, i.e. when the process is stopped, invoke:

stty susp ''; fg; stty susp ^Z

If this doesn't work for you, keep reading.


Possible problem, adjusted solution

In general programs may configure the terminal by themselves, so (depending on the program) it may happen that after you stty susp ''; fg, the program configures the terminal back (in a way equivalent to stty susp ^Z). To outsmart such program you can run stty susp '' from another terminal, yet addressing the original terminal, while the program is running. This is how:

  1. In the original terminal press Ctrl+Z to stop the program.

  2. Invoke tty. The output will be like /dev/pts/6 or /dev/tty4.

  3. fg the program, give it a second.

  4. In another terminal run </dev/… stty susp '', where /dev/… is the exact output you got from tty in the original terminal.


Notes

  • When "converting" of Ctrl+Z to SIGTSTP is disabled after stty susp '', Ctrl+Z will cause a byte 0x1A (often denoted as ^Z) reach whatever reads from the terminal (in your case: the program in question). This does not happen normally (and after stty susp ^Z), when the terminal intercepts this byte and "converts" it to SIGTSTP.

    For you this means that if the user tries Ctrl+Z then there will be no SIGTSTP (the behavior you want), but instead there will be input which in general may cause some (possibly unwanted) reaction of the program.

  • There is also stty -isig that disables checking of input characters against the special control characters: INTR (usually ^C), QUIT (usually ^\) and SUSP (usually ^Z, the question is about exactly this); stty isig enables them. See man 1 stty.


Viewing all articles
Browse latest Browse all 656

Trending Articles