Skip to content

Instantly share code, notes, and snippets.

@eidantoei
Created April 29, 2010 04:30
Show Gist options
  • Save eidantoei/383141 to your computer and use it in GitHub Desktop.
Save eidantoei/383141 to your computer and use it in GitHub Desktop.
timeout()
# timeout()
# fork from http://d.hatena.ne.jp/hcr/20050803/1123025377
# 2010-04-29
timeout()
{
count_timeout=$1
shift 1;
echo exec \'$@\'
$@ &
pid=$!
count=0
while [ ${count} -lt ${count_timeout} ]
do
if [ -e "/proc/${pid}" ]; then
echo ${pid} is alive.
count=`expr ${count} + 1`
sleep 1
else
echo ${pid} was disapeared.
count=`expr ${count_timeout}`
fi
done
if [ -e "/proc/${pid}" ]; then
kill -kill ${pid}
wait ${pid}
echo ${pid} was terminated by a SIG$(kill -l $?) signal.
fi
}
timeout 5 sleep 3
timeout 5 sleep 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment