How to raise and take care of shell scripts: Cleanup

Cleanup at script's end

Every program should do a little cleanup work before the final exit, that means: delete temporary created files, kill still running background children and so on. But a program can also be terminated from outside by sending a signal to it (the command to do such nasty things has the appropriate name kill). In this case there are two possibilities which can help you: A little programmer's discipline and trap:

There's no way to trap two signals: SIGSTOP and SIGKILL will always immediately terminate the process, if the caller has the permission to do that (is "root" or the process owner).