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

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

1 Answer 1

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

 
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.