LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-05-2008, 04:04 AM   #1
Murdock1979
Member
 
Registered: Oct 2003
Distribution: Slackware Debian VectorLinux
Posts: 429
Blog Entries: 2

Rep: Reputation: 30
Cron Timing


Hello!

I am wondering does a cronjob start another process if the job is triggered although the previous process has not yet finished yet? For example, a job is set to run every ten minutes and when ten minutes pass, the previous process is still running. So does the cronjob wait or just start a new process.

Is there any way to control this?

Thanks,
Murdock

Last edited by Murdock1979; 08-05-2008 at 05:30 PM. Reason: Thanks to Chris' Point
 
Old 08-05-2008, 04:30 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It starts a new process, despite a process with the same name or launched from the same crontab entry is still running. There are a lot of ways to control it, depending on the type of application and the ability to modify the executable. For example if it is a shell script you can put a "waiting" loop at the beginning of the script:
Code:
#!/bin/bash
while ps -C name_of_the_process > /dev/null
do
  sleep 5
done
This will repeatedly sleep 5 seconds until the previous process is terminated. Anyway, you may end up with multiple processes waiting for each other. If this is the case, maybe it's better to schedule the process with a longer time step.
 
Old 08-05-2008, 09:21 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
cron resolution is only to the nearest minute: http://www.adminschoice.com/docs/cro...Crontab%20file .
If you want better than that, write your own daemon (infinite loop) and just wait (eg sleep 10) if you want a minimum num of seconds between runs.
 
Old 08-05-2008, 05:25 PM   #4
kenoshi
Member
 
Registered: Sep 2007
Location: SF Bay Area, CA
Distribution: CentOS, SLES 10+, RHEL 3+, Debian Sarge
Posts: 159

Rep: Reputation: 32
Control it through your script, tried and true way would be:

Code:
if [ -e /tmp/already_started ]; then

   echo "I am already running as $(< /tmp/already_started), exiting" >> /tmp/some_error_log
   exit 1
    
else

   echo $$ > /tmp/already_started
   do_your_thang
   rm -f /tmp/already_started
   
fi
 
Old 09-27-2011, 04:02 PM   #5
ladoma
LQ Newbie
 
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
Talking

Quote:
Originally Posted by kenoshi View Post
Control it through your script, tried and true way would be:

Code:
if [ -e /tmp/already_started ]; then

   echo "I am already running as $(< /tmp/already_started), exiting" >> /tmp/some_error_log
   exit 1
    
else

   echo $$ > /tmp/already_started
   do_your_thang
   rm -f /tmp/already_started
   
fi
Thank you very much!! That was exact the code i was looking for.
Because to install flock ect. on my linkstation, my knowledge wasn't good enough ;-)

I am using(now) a linkstation mini(LS-WSGL) with rsync, that automatically sync to my online-storage(Strato Hidrive).

I edit my cronjob like this:
Code:
cd /etc/cron
crontab -e
I added following line:

Code:
*/1 * * * * /mnt/array1/share/rsync_hidrive_setup.sh
My rsync_hidrive_setup.sh looks like this:
Code:
#!/bin/bash

if [ -e /mnt/array1/share/already_started ]; then

   echo "I am already running as $(< /tmp/already_started), exiting" >> /tmp/some_error_log
   exit 1
    
else

   echo $$ > /mnt/array1/share/already_started
   rsync --delete --exclude=.* -avubzre ssh -i /root/.ssh/id_rsa /mnt/array1/share/rsync BENUTZER@rsync.hidrive.strato.com:/users/BENUTZER --backup-dir=deleted_rsync
   rm -f /mnt/array1/share/already_started
   
fi
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron.daily timing info (problem and solution) dannystaple SUSE / openSUSE 5 08-06-2008 07:31 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
how to start timing and print the timing result on portions of java codes ?? alred Programming 2 05-15-2006 10:00 AM
Cron Job Selective Timing kyosuke Linux - General 3 03-01-2006 09:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration