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.
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.
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.
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With