Why is it important

It is hard to get rid of something. This can be Britain trying to get rid of EU, a girl trying to get rid of her Ex or when you do ctrl + c you want to have the program to exit completely. And this is annoying. I am not in a good position to suggest a good way to deal with the first two things, but I can try to explain how to exit cleanly from a program.

Good contract between the caller and callee

When we quit our browser, we expect all the resources it was using to be freed. When we exit from our terminal, we expect all the running sub-processes to be exited when we close it. This might sound trivial, it is like everyone should know how to use the toilet and the contract between him/her using it and the next person who wants to use it. I am sure you have been into the situation when someone does not follow this contract.

It is dangerous to leave processes around

Homedir script (bash)

Garden containers (golang)

Solutions for the two problems

Top down

Bottom up

Good trick to know when we see the problem