[CentOS] Timeout for a script

Jussi Hirvi greenspot at greenspot.fi
Wed Nov 12 13:39:36 UTC 2008

Ian Blackwell (ian at ikel.id.au) kirjoitteli (12.11.2008 12:13):

> I put this little test script together.  It seems to work OK...
> #!/bin/bash
> timeoutseconds=5
> pid=$$
> (echo Will kill $pid in $timeoutseconds seconds; sleep $timeoutseconds;
> kill -1 $pid) &
> while true
> do
> echo Hello
> sleep 0.6
> done
> You may need to vary the signal in the kill statement, depending on what
> you're running.


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
background... 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

Then I found this, which leads me to believe it's not that simple:


(scroll to "Command timeout")

On that page, they recommend "a simple c solution" timeout.c, which you can
download here: 


Anybody bother to comment? How is that thing used? Sorry, I don't speak c.


Jussi Hirvi * Green Spot
Topeliuksenkatu 15 C * 00250 Helsinki * Finland
Tel. & fax +358 9 493 981 * Mobile +358 40 771 2098 (only sms)
jussi.hirvi at greenspot.fi * http://www.greenspot.fi

More information about the CentOS mailing list