Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Some applications only allow one running instance (like eclipse, if you want to use the same workspace). So if I log in from another location, I have to kill/close the application that was open when I previously logged in from another location.

I always use kill command to kill the running process. But, if you kill a process, it might not save some states that are useful for future usage. However, if you "close" it properly by clicking on the close button, for example, it will save the states properly.

Is there a way to properly "close" an application from command line? I know this can vary from applications, so let's be a bit more generic: how to send a signal to another running application, and this signal works just as if we click the "close" button in the top bar?

share|improve this question
Should we assume that accessing the desktop remotely with VNC and then graphically clicking close is too much overhead. – Brian Swift Mar 31 '12 at 5:53
up vote 17 down vote accepted

By default, the kill command will send SIGTERM (termination signal) to the running process. Unlike SIGKILL, which will forcibly kill the process with no chance to respond, the SIGTERM signal can be intercepted by the process, allowing it to terminate gracefully. Whether or not it actually does terminate gracefully is entirely dependent on the process itself; it can just as easily kill itself or ignore the signal entirely.

You can ensure that you are sending SIGTERM instead of some other signal by making it explicit on the command line thus:

kill -s TERM <pid>
share|improve this answer
Yeah, the OP's premise is false. The kill command attempts a graceful shutdown. If the application doesn't close down cleanly in that case, it's broken. (And the vast majority of applications are not broken.) – David Schwartz Mar 31 '12 at 8:58
Firefox seems to be (broken). If I run kill -s TERM <firefox-pid>, it will not shut down gracefully, and when I start it again, it asks me if I want to recover the crashed session. :sigh: – Wilson F Jun 19 '15 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .