当前位置: 技术问答>linux和unix
shell脚本设置command的timeout
来源: 互联网 发布时间:2016-09-14
本文导语: 一个shell脚本中, 有些command需要设置timeout,请问怎么办呢? | ./test.sh & { sleep ${TIMEOUT}; eval 'kill -9 $!' &> /dev/null; } | 安装timeout这个工具, Debian/Ubuntu可以 sudo apt-get install timeout timeout用法如下 ...
一个shell脚本中, 有些command需要设置timeout,请问怎么办呢?
|
./test.sh & { sleep ${TIMEOUT}; eval 'kill -9 $!' &> /dev/null; }
|
安装timeout这个工具,
Debian/Ubuntu可以
timeout用法如下
Debian/Ubuntu可以
sudo apt-get install timeout
timeout用法如下
TIMEOUT(1) TIMEOUT(1)
NAME
timeout - run command with bounded time
SYNOPSIS
timeout [-signal] time command ...
DESCRIPTION
timeout executes a command and imposes an elapsed time limit. The
command is run in a separate POSIX process group so that the right
thing happens with commands that spawn child processes.
Arguments:
-signal
Specify an optional signal to send to the controlled process.
By default, timeout sends SIGKILL, which cannot be caught or
ignored. The signal must be provided in its numerical value.
time The elapsed time limit in seconds after which the command is
terminated.
command
The command to be executed.
DIAGNOSTICS
timeout's exit status is the exit status of the specified command or 1
in case of a usage error.
LICENSE
The IBM PUBLIC LICENSE must be distributed with this
software.
HISTORY
This program was first released as part of SATAN.
AUTHOR(S)
Wietse Venema
TIMEOUT(1)
|
如果用bash, 可以用他的read -t sec,也可以用stty来实现。
shell的内部变量TMOUT只能限定在命令行下即交互模式
shell的内部变量TMOUT只能限定在命令行下即交互模式