The kill command sends a signal to the Unix process. This signal defaults to SIGTERM, which is a polite request to exit the program.
When a process exits for any reason, Unix OS cleans up its memory allocations, files, and other resources. The only resources that are not cleared are those that need to be shared, such as the contents of files and shared memory (such as System V IPC).
Many programs do not need to perform any special cleanup on exit and use the default behavior of SIGTERM, which allows the OS to stop the process.
If the program needs special behavior, it can install a signal handler, and then it can run a function to process the signal.
Now the SIGKILL signal, which is number 9, is evil, but also necessary. This signal never reaches the process itself, the OS just stops the process. This should be used when really, really necessary. This often becomes necessary in multithreaded programs that get into deadlocks or programs that have installed a TERM signal handler, but are screwed during their release.
source share