I am trying to use pidof or pgrep to be able to send a HUP to a process in my system. The problem is that I only want to kill the process with a precise parameter.

This is the output of 'ps awx'

  657 ?        S      0:00 processname software
  658 ?        S      0:00 processname demo
  659 ?        S      0:00 processname test

By doing one of these:

pidof processname 
pgrep processname

You get the list of all the processes starting by processname, but i'd like to do something like:

pidof processname test
pgrep processname test

To retrieve only the PID I need (in this example would be 659)


By using the -f flag on pgrep just does what I wanted, by doing:

pgrep -f "processname test"

You'll get the right answer.

  • Right, you generally need -f because you want to match on the full command line. Note that pgrep operates on regular expressions, so you can do relatively complex matching, also.
    – cjc
    May 15 '12 at 10:00
$ ps aux |grep [d]evio
user01   10220  0.0  0.1   5376  2424 pts/5    S+   11:41   0:00 ssh devio
$ pgrep -f "ssh devio"
$ pkill -0 -f "ssh devio" ; echo $?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.