Created
March 16, 2014 09:47
-
-
Save mtayseer/9580855 to your computer and use it in GitHub Desktop.
One-liner which kills a Unix process given its name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Kill a process, given part of its name | |
# | |
# How I'm doing it:- | |
# | |
# 1. Get a list of all processes | |
# 2. Grep for any process where "portal" is part of the | |
# command line used to launch it | |
# 3. I will get 2 processes: 1 of them is what I'm searching for & | |
# the other is just this grep command I'm running. I remove it by | |
# removing anything with "grep" in its command line | |
# 4. Get the 2nd column (the process ID) | |
# 5. kill this process | |
kill -9 `ps -ef | grep portal | grep -v grep | awk '{print $2}'` |
killall portal
I didn't know about killall
before, but it's easier of course. I think that my solution works on other Unix systems as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not killall ?