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 have a cronjob that is set to run constantly. It's a php file that streams data from twitter. However twitter goes down every once a while or we lose connection so I have cron checking back every minute to try and run the file. The php script checks a lock file to make sure multiple copies are not run. The thing is this script will run for hours on end and I want to be able to kill it. However I can't seem to find it using commands like

ps ux

The cronjob was started with my user and I have looked to see it under root. I cannot seem to find the process running at all.

I am using

/usr/bin/php /var/www/twitter/stream.php

to execute in my cron file and I know it is running because every minute it writes a file to a directory. I can stop cron, but the process keeps going, I simply need to kill it. Not sure if this belongs here or on Stack Overflow.

share|improve this question

3 Answers 3

up vote 3 down vote accepted

To show daemons in ps you need to include the -e option (System V/POSIX) or a (BSDish). Try ps aux or ps -ef.

share|improve this answer

You're Doing It Wrong. (At least in my humble opinion :-)

You can do what you want the way Geekosaur or James Yale suggested, but I think you really want PHP's pcntl_alarm() function (and its relative pcntl_signal) which will allow your PHP script to take advantage of the SIGALRM facility and kill itself when things go wrong.

What you do with the alarm clock is your call (it can be as simple as "Exit if I've been running for an hour" or as complex as "Check to see if we've gotten data from twitter. If not re-initialize the connection, and if we still don't get data exit and let the script run again later" - it all depends on how complex your script is).

More questions on SIGALRM and signal handling should probably go to StackOverflow - they're (hopefully) familiar with it and can give you more guidance from a programming point of view :-)

share|improve this answer

Usually processes write the PID into the lockfile, that way you can find both if the process is running and what it's ID is in one place.

I'd suggest you modify your script to do that, then you can just posix_kill or similar it as required.

share|improve this answer

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.