Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Gracefully" killing a process

Right now I am using Process.Kill() to kill a process. Is there a way though, instead of just killing it immediately, that I can like send a message to the process instructing it to close so that it can gracefully clean up and shut down. Basically, I'm looking for the equivlent to just clicking the red X in the upper right hand corner, which I believe DOES send a message to the application requesting a shut down.

like image 944
Icemanind Avatar asked Aug 05 '10 05:08

Icemanind


People also ask

Which signal gracefully terminate the process?

The right signal for termination is SIGTERM and if SIGTERM doesn't terminate the process instantly, as you might prefer, it's because the application has chosen to handle the signal.

How do you kill a process?

To kill a process use the kill command. Use the ps command if you need to find the PID of a process. Always try to kill a process with a simple kill command. This is the cleanest way to kill a process and has the same effect as cancelling a process.


1 Answers

If the process has a windows interface (as you refer to the red "X"), you can try Process.CloseMainWindow(). If it fails, you can fallback to Process.Kill().

like image 56
lc. Avatar answered Oct 14 '22 06:10

lc.