1844088 Members
2583 Online
110227 Solutions
New Discussion

Run the process

 
hanyyu1
Advisor

Run the process

In my server , there is a process need to keep on running , this processs may take 5-10 mins to run ( depends the situation ) , if I add a cron to run this job in every 5 mins ( eg. */5 ) , there will be two duplicate process in the system , if add a cron to run in every 10 mins , then there may be no job is running for 5 mins , is it possible to make sure the job is running but don't have a duplicate job ? thx
4 REPLIES 4
RAC_1
Honored Contributor

Re: Run the process

Why not?? Run job through cron every 10 minutes. The script first should check if another instance of job is running or not. If running, it will not run another instance and if not running it will start one.

Following code will do that.

job_status=$(UNIX95= ps -C"process_name"|wc -l)

if [[ ${job_status} -gt 0 ]]
then
"start_your_job"
else
exit #not starting the job
fi
There is no substitute to HARDWORK
Muthukumar_5
Honored Contributor

Re: Run the process

You can leave cron idea here.

Start a process and check for process completion with it's PID using ps command. Start again once it is completed.

./process &
pid=$!;

check with this $pid variable using while loop.

-Muthu
Easy to suggest when don't know about the problem!
Yogeeraj_1
Honored Contributor

Re: Run the process

hi,

there is also the possibility to use the script itself to reschedule itself using the "at" command. See man at


e.g.

echo "$util/yourscript.sh"|at `< /dev/null

so that it gives something like:
echo "$util/yourscript.sh"|at 8:00am > /dev/null

hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Hemmetter
Esteemed Contributor

Re: Run the process

Hi hanyyu1

What about an inittab(4) entry for this?

Then init(1) will observe that process and respawn a new one when the old one termiates.


rgds
HGH