Last active
May 3, 2017 16:22
-
-
Save pagxir/5f9ab9179a1a5c0fd8b00badd5cff0bf to your computer and use it in GitHub Desktop.
execute a shell command with 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() { | |
exec 4<&1; | |
(sh -c 'echo $PPID'; exec $@ 3<&1 1<&4 4>&-) | (cat; echo END;) | (read PID; read -t 3 || kill $PID) | |
exec 4>&-; | |
} | |
timeout wget http://www.baidu.com/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment