Skip to content

Instantly share code, notes, and snippets.

@mtayseer
Created March 16, 2014 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtayseer/9580855 to your computer and use it in GitHub Desktop.
Save mtayseer/9580855 to your computer and use it in GitHub Desktop.
One-liner which kills a Unix process given its name
# 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}'`
@mos3abof
Copy link

Why not killall ?

@mos3abof
Copy link

killall portal

@mtayseer
Copy link
Author

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