A quick way to find a running process that you know the name of is to use ps:
or to filter out the grep process:
Then to kill it you could use kill and the PID (Process ID) reported by ps:
That does works, but it’s cumbersome to type, especially if you’re killing things often, so let’s look at a better way…
For demonstration purposes, let’s setup a python SimpleHTTPServer and detach it from the command line:
We can now see the PID ps as before:
But we can also use pgrep
Here the -f option allows pgrep to search the process name and it’s arguments, and the -l option lists the process name in it stdout instead of just the PID by default.
Now that we know that pgrep has found our process, we can use pkill to terminate it:
And we can check it’s died using pgrep again:
If you’ve got a stubborn process, you can also send an optional signal to pkill, just as you can with kill, just make sure it’s the first argument:
So to recap, find your process by name with pgrep (optional) and terminate it by name with pkill:
Tags: Linux
Posted on 07 May 2013. blog comments powered by DisqusRecent Posts:
How to monitor the progress of a dd process, even after it has started.
Monitoring frequency drift on the RTL SDR dongle
High entropy passwords are serious business! Here some little helpers to create better ones.
Running Linux and need to look busy quick? Try this little bit of command line fun :)
Bash scripts and command line examples are often littered with ampersands. Here's what they do.