NAME

timeout - Send a signal to a program after a certain time.


SYNOPSIS

timeout [-s signal] [-v] [-g] -t seconds | seconds program [args]


DESCRIPTION

timeout executes a program (with arguments args) and sends a signal to it after a certain amount of seconds.


OPTIONS

-s signal

Signal to send to the spawned process. This can be a numerical or symbolic ID. This defaults to TERM.

The default is TERM followed by KILL.

-t seconds | seconds

Number of seconds timeout waits for the program before sending a signal. You can use either -t seconds or just seconds without -t. The latter is for compatibility with Linux timeout program in netatalk package.

-g

Send signal to all processes in process group. If the program spawns new processes, all the processes in the group will be killed. Please see the example in EXAMPLES section below to decide when to use and not to use this option. This option is not used by default.

-v

Verbose mode.


EXAMPLES

timeout 10 pap foo.ps

Execute ``pap foo.ps'' and send a SIGTERM if pap doesn't return after 10 seconds.

timeout -s HUP 60 sh

Spawn a shell and send a hangup signal after one minute.

timeout -s 9 10 evilprog

Execute a program and KILL it if it doesn't quit after 10 seconds.

timeout -gv -s 15 -t 3 trap.ksh

Send a signal to a program which traps the signal:

  trap 'echo got signal 15' 15
  /bin/sleep 7

Because the program traps the signal, it is normal termination (not killed). Because -g is used, ``/bin/sleep'' child process is killed with return code 143 (128+15). Because ``/bin/sleep'' is the last statement in the trap.ksh script, its return code will be the return code of trap.ksh script. Therefore, you get:

  "normal termination, exit status = 143."

(If you have ``exit N'' after /bin/sleep, then exit status of trap.ksh will be N.)

If you do not use -g option, ``/bin/sleep'' will NOT be killed, the trap.ksh will sleep for 7 seconds, and terminate normally with exit status 0.


REVISION HOSTORY

version 2.0, 2008-07-24, Michael Wang <xw73@columbia.edu>.

- Added compatibilities with Linux timeout program in netatalk package. Copied part of Linux source code and man page.

- Compatible exit code for killed program with shell.

- -g option.

version 1.1, 1998-04, Michael Wang <xw73@columbia.edu>.

- Incorporated code from Stefan `Sec` Zehl <sec@42.org>: ``It prints to stderr now and has a switch to remain completely silent. It compiles on BSD the way it is now, and a small buglet (when omitting -t it cored here) was fixed.''

- setpgrp was added. kill(-pid, signal) was used to kill the ps group.

version 1.0, 1998-02, Michael Wang <xw73@columbia.edu>.

IPO.