Killing parent processes

Let's say I have a process tree like

crond - crond - process1 - process2 - cat                     
                                    | - process3 - process4

what happens if I kill process1?

1 Like

I think this depends on how you kill it. Off the top of my head some options will kill the process and leave everything behind. Others will let the parent clean up and kill the children. You can kill by group process I'd as well.

2 Likes

So killall process1 kills everything "downstream"? Kill process1 toasts process1 but not the rest? Maybe the rest complete but then rest of process1 won't run?

if its all bash scripts then they all die. If its mixed with Python or similar. Chance is stuff stays alive till the process is done. Depending how its programmed.

3 Likes

If you kill process1 all the processes consecutive to it will be killed. That happens because the other processes in that branch are using code and data from the parent process so, if you kill it, they don't have any resource to work on anymore so they just die.
This is not a "clean" way to act because you'll be forcing the other processes below process1 to die. A good practice is kill son processes one by one from the bottom up to avoid issues. I know you're asking for knowledge and not to do things this way, I just wanted to be more precise.

1 Like

This isn't strictly true. I'm not completely familiar with processes and signals, but when you kill a parent you aren't guaranteed to kill the children. Children left will be adopted by PID 1. If you want to kill the parent and children you need to kill the whole group using their PGID.

2 Likes

looks like this answers your question.

1 Like