Unix & Linux
linux terminal signals sighup
Updated Sat, 20 Aug 2022 06:12:37 GMT

Who sends SIGHUP to the controlling process of the pseudoterminal when the terminal emulator terminates?


When a terminal is disconnected, the OS kernel sends SIGHUP to the controlling process of the terminal.

When a terminal emulator terminates, who sends SIGHUP to the controlling process of the pseudoterminal underlying the terminal emulator: the OS kernel or the terminal emulator?

Thanks.




Solution

The answer is already contained in your question. When a terminal is disconnected, the kernel sends SIGHUP to the controlling process of the terminal. For a terminal created by a driver in the kernel, the terminal is disconnected when the driver says so. For a pseudoterminal, the terminal is disconnected when the file handle for the master side of the terminal is closed (either because the terminal emulator process closed it explicitly or because the terminal emulator process died).

The controlling process is whatever process ran first in the terminal more precisely, it's the first process that either opened the terminal while being a session leader or became a session leader while having the terminal open, if this process still is a session leader.
The master side is the side of the emulator. The slave side is the side of the application running in the terminal.
If more than one process has the master side of the terminal open, they must all close their file descriptors (possibly by dying), so that the file descriptor is closed.