I want to use ps -ef | grep "keyword"
to determine the pid of a daemon process (there is a unique string in output of ps -ef in it).
I can kill the process with pkill keyword
is there any command that returns the pid instead of killing it? (pidof or pgrep doesnt work)
To kill a process by a specific keyword you could create an alias in ~/.bashrc
(linux) or ~/.bash_profile
(mac).
alias killps="kill -9 `ps -ef | grep '[k]eyword' | awk '{print $2}'`"
ps -ef | grep KEYWORD | grep -v grep | awk '{print $2}'
Try
ps -ef | grep "KEYWORD" | awk '{print $2}'
That command should give you the PID of the processes with KEYWORD in them. In this instance, awk
is returning what is in the 2nd column from the output.
I use
ps -C "keyword" -o pid=
This command should give you a PID number.
This is available on linux: pidof keyword
Source: Stackoverflow.com