cunixprocess

Can I kill a process from itself?


I have some code that is executed when the process is killed, can I actually call kill(getpid()) to force the execution of this code (and close the process obviously)?


Solution

  • Yes, you can. There's even a specific function for it — raise(sig) — although kill(getpid(), sig) will work too.