[CentOS] Timeout for a script
filbranden at gmail.com
Wed Nov 12 14:19:26 UTC 2008
On Wed, Nov 12, 2008 at 08:39, Jussi Hirvi <greenspot at greenspot.fi> wrote:
> Thanks - but I couldn't make that work as expected. It seems to kill
> *something*, but after that, the rsync part still continues in the
If what you want to kill is the rsync process, do the opposite, run
rsync in background, sleep for some time, test if it is still running
and then kill it.
> Here's my last test:
> (sleep $timeoutseconds;
> echo `date '+%c'` " $0 INTERRUPTED" >>$log;
> kill -9 $pid) &
> /usr/bin/rsync -avzu --delete /root /home/palvelimet/bckserver1
> echo `date '+%c'` " $0 valmis" >>$log
Use something like:
/usr/bin/rsync -avzu --delete /root /home/palvelimet/bckserver1 &
# test if process $rsync_pid is still a child of this process:
ppid_rsync=`ps -o ppid= "$rsync_pid"`
# remove any spaces
# compare the parent of $rsync_pid with this process, if it matches,
test x"$ppid_rsync" = x"$$" && kill "$rsync_pid"
It's certainly more convoluted than it should be... but it should work.
The C solution is probably the right thing to do, if you have time to
dig into it and find out how it works.
More information about the CentOS