Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)

UPDATE

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

pgrep -f "processname test"

You'll get the right answer.

share|improve this question
    
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

1 Answer 1

up vote 2 down vote accepted
$ 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"
10220
$ pkill -0 -f "ssh devio" ; echo $?
0
share|improve this answer
    
Thanks, -f was the key :) –  Aseques May 15 '12 at 9:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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