but cronjob does not have a time out.
i found a code for shellscript on the internet:
Code:
my_command & sleep 5
kill -0 $! && kill $!
seems like I can run my algorithm, put it to sleep, and then kill it. but what does the parameters for kill mean? does anyone knows?
Someone posted this code below and I seek help from other forum. You guys know what it means? Sorry, I'm a newbie in shell scipt... =)
Code:
#!/bin/bash
# Signal handler for SIGALRM.
#
on_timeout()
{
echo "Time out! Exit..."
exit 3
}
# Timer function.
# - First argument: PID to send SIGALRM to.
# - Second argument: time-out in seconds.
#
timeout_timer()
{
sleep $2
kill -s SIGALRM $1 >/dev/null 2>&1
}
# Set signal-handler function
#
trap 'on_timeout' ALRM
# Start time-out timer in the background.
# Set time-out to 4 seconds.
#
timeout_timer $$ 4 &
# Main part of the script, which will time out.
# Here: just looping forever, or until time-out
#
SEC=0
while true ; do
sleep 1
SEC=$((SEC+1))
echo "I'm PID# $$, and I'm alive for $SEC seconds now!"
done
# We never get here.