Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 24th, 2011, 02:44 PM
beebac beebac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 107 beebac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 8 m 18 sec
Reputation Power: 3
Crontab help - prevent duplicate process

Hi. I know how to set crontab to make a program run but is there a way or additional syntax/code I can add to the line of my cron job that whenever it runs the program it will check whether there's a process already running?

Reply With Quote
  #2  
Old July 24th, 2011, 03:49 PM
kicken's Avatar
kicken kicken is offline
Wiser? Not exactly.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2001
Location: Bonita Springs, FL
Posts: 5,654 kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)  Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 2 Months 2 Weeks 2 Days 5 h 1 m 44 sec
Reputation Power: 3436
Have your cron job launch a shell script which checks if the process is running. If it is running, your shell script just exits without doing anything. If it is not running, your shell script would launch it.

There are various ways to test if a process is running. A most common one is to record the PID when launching the process in a file somewhere. Your shell script can then test if that file exists, and if so check the the process specified by that pid is still running using the ps command.
__________________
Recycle your old CD's, don't just trash them


Spidermonkey Tutorial;

If I helped out out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

Reply With Quote
  #3  
Old July 24th, 2011, 04:20 PM
beebac beebac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 107 beebac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 8 m 18 sec
Reputation Power: 3
That seems a bit hard for me as I don't do shell script. I just know how to set up the line on crontab.

But I found this and it seems using flock. It doesn't explain much though. I'm wondering if it means when the script runs it creates a file which has a lock and will auto remove once it's done.

So if the next job starts and see there's a lock then it won't lock again which means this next job will stop?

Is this correct?

http://blog.0x1fff.com/2011/01/cron-tip-prevent-running-multiple.html

Reply With Quote
  #4  
Old July 24th, 2011, 04:42 PM
beebac beebac is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 107 beebac User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 8 m 18 sec
Reputation Power: 3
Hi. I just found this and it seems pretty good. My script is php.

Here's the link for those one who's interested.

http://abhinavsingh.com/blog/2009/12/how-to-use-locks-in-php-cron-jobs-to-avoid-cron-overlaps/

Thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Crontab help - prevent duplicate process

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap