Issue
It's clear that a keyboard interrupt can stop code executing in a command shell on various operating systems. However, what happens when a window is closed that also causes code to stop executing?
Solution
Well it may interrupt on not. What actually happens is that a window hosts a shell (cmd.exe on Windows, xxsh on Posix systems). And all code executing in the window has that shell as ancestor. On Posix system, when the window closes it sends a SIGHUP signal to its shell which sends it in turn to its children.
So there are two way for a code executing in that window to survive the closure:
- explicitely ignore SIGHUP (there is even a command dedicated to that which is
nohup
) - have an intermediary process to exit. When this happens, its children are adopted by the
init
process (PID 1) and no longer depend from the window and its main shell
Remark: this only makes sense for Unix-like like various Unix systems like the xxxBSD, Linux, or recent versions of MAC OS for which the underlying system is Darwin, a derivative from BSD, but does not apply to Microsoft Windows.
Answered By - Serge Ballesta Answer Checked By - Senaida (WPSolving Volunteer)