Kill both parent and child processes

killprocess

I am running a bash script as a background job. The bash script calls a time-consuming executable. If I am not wrong, the running of the bash script is the parent process and the running of the executable is the child process.

(1) when I look at the output of top, it only shows the child process which is the running of the executable, not shows the parent process which is the running of the script. Just wonder why not show both? And how to show both?

(2) I now want to stop the whole running by killing the parent process which is the background job

kill -9 $(jobs -p)

The terminal shows that the running of the bash script is killed. But the running of the executable still hangs on the output of top. I just wonder how to kill both parent and child process?

Thanks and regards!

Best Answer

Use a negative PID to kill a process group. Try to avoid -9 unless absolutely necessary.