Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>See the <a href="http://www.pixelbeat.org/scripts/timeout" rel="noreferrer">http://www.pixelbeat.org/scripts/timeout</a> script the functionality of which has been integrated into newer coreutils:</p> <pre><code>#!/bin/sh # Execute a command with a timeout # License: LGPLv2 # Author: # http://www.pixelbeat.org/ # Notes: # Note there is a timeout command packaged with coreutils since v7.0 # If the timeout occurs the exit status is 124. # There is an asynchronous (and buggy) equivalent of this # script packaged with bash (under /usr/share/doc/ in my distro), # which I only noticed after writing this. # I noticed later again that there is a C equivalent of this packaged # with satan by Wietse Venema, and copied to forensics by Dan Farmer. # Changes: # V1.0, Nov 3 2006, Initial release # V1.1, Nov 20 2007, Brad Greenlee &lt;brad@footle.org&gt; # Make more portable by using the 'CHLD' # signal spec rather than 17. # V1.3, Oct 29 2009, Ján Sáreník &lt;jasan@x31.com&gt; # Even though this runs under dash,ksh etc. # it doesn't actually timeout. So enforce bash for now. # Also change exit on timeout from 128 to 124 # to match coreutils. # V2.0, Oct 30 2009, Ján Sáreník &lt;jasan@x31.com&gt; # Rewritten to cover compatibility with other # Bourne shell implementations (pdksh, dash) if [ "$#" -lt "2" ]; then echo "Usage: `basename $0` timeout_in_seconds command" &gt;&amp;2 echo "Example: `basename $0` 2 sleep 3 || echo timeout" &gt;&amp;2 exit 1 fi cleanup() { trap - ALRM #reset handler to default kill -ALRM $a 2&gt;/dev/null #stop timer subshell if running kill $! 2&gt;/dev/null &amp;&amp; #kill last job exit 124 #exit with 124 if it was running } watchit() { trap "cleanup" ALRM sleep $1&amp; wait kill -ALRM $$ } watchit $1&amp; a=$! #start the timeout shift #first param was timeout for sleep trap "cleanup" ALRM INT #cleanup after timeout "$@"&amp; wait $!; RET=$? #start the job wait for it and save its return value kill -ALRM $a #send ALRM signal to watchit wait $a #wait for watchit to finish cleanup exit $RET #return the value </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload