Command Line – How to Soft Kill GUI Applications via Terminal

command lineguikillsignals

Is there a way to close a GUI application in friendly "please quit yourself now" way, without graphical access to the applications window?

For example, if Gnome/X display crashes to black, I'd like to switch to tty2 and close applications like firefox in a way which lets them save their config etc. At best without further user queries.

Best Answer

Usually, you can use SIGHUP to "friendly" close an application (with or without graphical interface).

kill -HUP <application_pid>

EDITED: added some other info

The way SIGHUP is handled is application dependent so, as Dave noted, it can happen that this signal is masked or handled. However quite all interactive applications exit gracefully with a SIGHUP.

On the other side, I have to admit that usually I follow this schema:

kill -HUP <application_pid>
# check if application is still running
kill -INT <application_pid>
# check if application is still running
kill -KILL <application_pid>

Obviously the last command is not so "friendly".

Related Question