Linux Tutorial Blog

Your regular Linux tutorial source!

Solution: Gently killing a process

rechosen | 31 January, 2007 14:52

Sometimes you somehow can't quit a certain process, but you don't want to lose all unsaved data by killing it. You can then try giving it a SIGQUIT. This solution describes how.

Please note that, if a process is not responding at all, chances are that it won't respond to a SIGQUIT. You can then try giving it a SIGKILL (just use the commands listed below but replace SIGQUIT with SIGKILL). The signal SIGKILL has an even higher priority than SIGTERM, the signal that killall and kill defaultly give to a process.

You can give all processes with a certain name a SIGQUIT this way:

killall -s SIGQUIT <processname>

Of course, you might also want to quit a process with a certain pid. You can do that this way:

kill -s SIGQUIT <pid> 

To find out a process' pid, have a look at the list that this command generates:

ps aux

If you (partly) know the name of the process, you can also grep for it so you won't have to read the whole list:

ps aux | grep <partoftheprocessname>

The above command consists of two parts: ps aux generates a list which is passed to grep by bash, and grep searches every line of ps aux's output for the string <partoftheprocessname>. Grep's searching is case-sensitive, you can also search case-insensitive this way:

ps aux | grep <partoftheprocessname> -i

By the way, you probably noticed that both command find themselves everytime you run them. This is normal, you should ignore this line. If the command only finds itself, then there is no process running of which the name contains <partoftheprocessname>. Example:

[rechosen@localhost ~]$ ps aux | grep crond
root      2067  0.0  0.1   5184   640 ?        Ss   10:29   0:00 crond
rechosen  6498  0.0  0.1   3912   652 pts/3    R+   15:12   0:00 grep crond

In the above case, the process crond with pid 2067 is what you're looking for. And in this case:

[rechosen@localhost ~]$ ps aux | grep bind
rechosen  6514  0.0  0.1   3912   652 pts/3    R+   15:14   0:00 grep bind

bind is not running, as grep only finds itself.

Comments

Re: Solution: Gently killing a process

stnzgr | 31/03/2007, 21:51

one can also use the "pidof" command. Eg: pidof bash

Very nice site btw

Add comment

(optional, will not be published)
(optional)

<><