LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   linux cron job duplicate job question (http://www.linuxquestions.org/questions/linux-newbie-8/linux-cron-job-duplicate-job-question-754264/)

cpthk 09-10-2009 05:13 PM

linux cron job duplicate job question
 
Hi:

I am setting up linux cron job. I was wondering if I set the cron job to wake up every minute. My process may take several minutes. Will there be a duplicate process issue?

For example, I am running a.out program. This program in busy load may take 5 minutes to finish. I need to set my corn job to run every minute. Will the linux cron run before the previous one finishes? Or it will wait for the previous one to finish? Or it will not run at all if the previous is still running?

I really need to set the cron as every minute for particular reason. Even I set it for a longer time, the program could still run longer than that depends on the load.

Thanks.

TB0ne 09-10-2009 05:21 PM

Quote:

Originally Posted by cpthk (Post 3677959)
Hi:

I am setting up linux cron job. I was wondering if I set the cron job to wake up every minute. My process may take several minutes. Will there be a duplicate process issue?

For example, I am running a.out program. This program in busy load may take 5 minutes to finish. I need to set my corn job to run every minute. Will the linux cron run before the previous one finishes? Or it will wait for the previous one to finish? Or it will not run at all if the previous is still running?

I really need to set the cron as every minute for particular reason. Even I set it for a longer time, the program could still run longer than that depends on the load.

Thanks.

No, it will spawn another job, and you'll have several all running at the same time.

And setting up a process that you know will take longer than a minute to complete, to run every minute, seems like a bad idea. Why don't you put a sleep statement into your script, so it'll pause for one minute, after each run? Then just run it with "nohup <script name> >/dev/null &", and it'll background and run just fine.

chrism01 09-10-2009 05:43 PM

As per TB0ne, every minute is overkill and will hammer your system creating a whole new process environment each time.
Plus, if they're processing the same data, it'll screw up.
Create a daemon as he said; personally I'd add logging, so

nohup prog >prog.log 2>&1 &

cpthk 09-11-2009 07:04 PM

I am actually running a perl script. The perl script will call a c++ program. So in perl script how do I sleep for a minute?

TB0ne 09-11-2009 08:52 PM

Quote:

Originally Posted by cpthk (Post 3679400)
I am actually running a perl script. The perl script will call a c++ program. So in perl script how do I sleep for a minute?

sleep(<seconds to sleep);

Check perldoc or CPAN for more info.


All times are GMT -5. The time now is 02:52 PM.