Created
April 29, 2010 04:30
-
-
Save eidantoei/383141 to your computer and use it in GitHub Desktop.
timeout()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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