Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I created a cronjob, it runs for a very long time but now don't know how to stop it. Please help.

share|improve this question

migrated from stackoverflow.com Jan 17 '12 at 13:35

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 1 down vote accepted

You should stop the process that the crontab started running.

#kill -HUP PID (PID: Process ID is the process running)

To see a relation of the PID with the running processes (and more info) use top command, change the column order with the keys < and >

Also try ps -ax|grep [your_process_file] which lists the running processes filtered by the name you choose

-HUP = Hang UP

share|improve this answer
    
I typed "top" but didn't see my cron in the list. –  Emerald214 Jan 16 '12 at 11:57
    
You shouldn't see cron or crontab, you are be looking for the process that you cron just run. By the way, if you edit your cron (crontab -e), erase the cronjob line and save, your process won't run again –  Nacho Jan 16 '12 at 12:01
    
I created a cron running update_user.php. When I typed "top", there is no process with name "update_user.php", I just see a list with "mysqld", "php", "init", ... How to know my cron's PID? –  Emerald214 Jan 16 '12 at 12:03
    
How was the cronjob call? was it something like 0 0 * * * /var/www/update_user.php? –  Nacho Jan 16 '12 at 12:05
    
Yes! Something like this 50 3 1 * * /usr/local/bin/php -f /home/www/xxx/libs/update_user.php. I'm sure it started. –  Emerald214 Jan 16 '12 at 12:07

I think if a shell-script wrapper is around that should timeout the cronjob, if it is running for a lengthy arbitrarily enough long periods of time. The wrapper should send the SIGHUP or SIGALARM when the timeout happens from the period the cronjob is invoked. Something like this:

50 * * * * /usr/bin/my_cron_wrapper_timeout -t 1 /usr/bin/my_command_cron_job_to_run

This cron_wrapper_timeout should basically send the timeout signal once -t switch option 1 hour passes and then should send kill -HUP signal to the cronjob and then make sure to reap the process as well and then end/kill itself.

Or alternatively, the code should be written with in the cronjob itself to handle the ALARM signal timeout and make sure it cleans up before it dies gently.

EDIT

This is exactly what I was referring to: watchdog at http://chihungchan.blogspot.com/2011/03/no-more-hanging-jobs-in-cron.html

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.