Hacker News new | past | comments | ask | show | jobs | submit login

If we're going down the rabbit hole of pedantry, you could also say CTRL+Z doesn't send SIGTSTP, it's just a character sent to your shell. The shell will often send a SIGTSTP, but it can do whatever it likes, including nothing at all.

That said, custom behavior for SIGTSTP is about as common as a shell environment that doesn't send SIGTSTP on ctrlz.




Well, if you really want to go down the rabbit hole...

The shell only gets CTRL+Z when it is in the foreground.

The tty driver, which contains a copy of the forground process group id, sees the CTRL+Z, and rather than buffering it to pass to the foreground process, interprets it to send a SIGTSP to the process group that is in the foreground. A well behaving program will either handle the SIGTSTP then send itself a SIGSTOP or just act as if SIGSTOP has been sent. Then a SIGCHLD will be sent to the parent process. (In this case the shell) which can then set another process group or process, including itself, to the foreground process.

Some of the details may vary depending on the terminal line discipline being used... but the important part here is:

The shell isn't actually getting the CTRL+Z, its handled by the tty/pty pair that is in charge of the input at the moment.

Fascinating page about all this here: http://www.linusakesson.net/programming/tty/index.php


something something keyboard sends electrons across a wire something something


Being specific about which signal is sent, especially if it deals with important nuances such as whether you can change the handler or not, isn't pedantry.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: