Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get the pid of a php script:

php /var/www/html/test.php

I have a couple of other php scripts running as well, for instance

php /var/www/html/hello.php
php /var/www/html/world.php

When I run pidof -s -x php /var/www/html/test.php, it randomly gives me the pid of any of the 3 running scripts. I think it's because it's only seeing the php after -x and ignoring the rest. I tried it with quotes and I didn't get any result at all.

pidof -s -x 'php /var/www/html/test.php'
share|improve this question
What you are actually asking pidof to do is to give you a single result (-s), also checking for scripts (-x), of either "php" or "/var/www/html/test.php". I suspect you are assuming pidof will AND the results, which it doesn't. Removing "php" from the command line is probably more what you want. – Drew Bloechl Feb 7 '11 at 21:59
I tried that and that didn't work either. – gAMBOOKa Feb 8 '11 at 7:26
up vote 5 down vote accepted

Give this a try:

pgrep -f 'php /var/www/html/test.php'
share|improve this answer
Works perfectly! Thanks! – gAMBOOKa Feb 7 '11 at 19:22

Your Answer


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.