I used ping
in a gnome-terminal
window and I can confirm your observations. I think it is problematic, that a process can be left running without anywhere to communicate. I will try to interpret what I notice (but I do not claim that I understand why, maybe to allow programs with an own GUI to work without nohup
after exit from bash
, when started in a terminal window).
When I exit
I am exiting from bash
running in the terminal window, and ping
continues to run, but has nowhere to write.
When I kill
the process, I kill the bash
process in the terminal window. I did not find an explicit gnome-terminal
process to kill, because the process /usr/lib/gnome-terminal/gnome-terminal-server
runs them all. I am not sure that this is what you were doing, but it is what I guess.
When I close the window (with the x button) I exit from the window process (which in turn forces its child processes to stop including bash
and ping
). This is an obvious difference from the two previous cases.
When I do the corresponding exercise with xterm
, there will be a separate process with the name 'xterm'.
When I exit
I am exiting from bash
running in the terminal window, and ping
continues to run, but has nowhere to write.
When I kill
the process, I kill the xterm
process of the terminal window, (which in turn forces its child processes to stop, including bash
and ping
).
When I close the window (with the x button) I exit from the window process (which in turn forces its child processes to stop, including bash
and ping
).
You know already, that you can use nohup
(together with &
) if you want the child process to continue after closing the terminal window, where child process was started.
Edit 1: Final comment:
From man bash
If a command is terminated by the control operator &, the shell
executes the command in the background in a subshell. The shell does
not wait for the command to finish, and the return status is 0.
We have noticed that there is no signal to stop the subshell and the process started in/from that subshell, when bash
is exited, at least not when run in a terminal window. But the calling terminal window is closed. I think, that after bash is exited, the terminal window no longer knows of the subshell and the process started in/from that subshell, and therefore it cannot stop them.
Edit 2: I asked for help at Unix & Linux - Please read the answers.