Timeout is a wonderful Linux Command that can control the running time of the program, which is very useful for controlling the running time of the program.
Timeout on the CentOS 6 platform, from the software package coreutils
# which timeout/usr/bin/timeout# rpm -qf /usr/bin/timeoutcoreutils-8.4-19.el6_4.2.x86_64
The principle of timeout is very simple. It is a simple timer and a kill command, where-s can be used with the kill parameter. It depends on how to kill it.
Man timeout is only half a page, as shown below
TIMEOUT(1) User Commands TIMEOUT(1)NAMEtimeout - run a commandwith a timelimitSYNOPSIStimeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...timeout [OPTION]DESCRIPTIONStart COMMAND, and killit ifstill running after NUMBER seconds. SUFFIX may be ‘s’forseconds (the default), ‘m’ forminutes, ‘h’forhours or ‘d’ fordays.Mandatory arguments to long options are mandatory forshort options too.-s, --signal=SIGNALspecify the signal to be sent on timeout. SIGNAL may be a name like ‘HUP’ or a number. See ‘kill-l‘ fora list of signals--help display this help and exit--versionoutput version information and exitIf the commandtimesout, thenexitwith status 124. Otherwise, exitwith the status of COMMAND. If no signal is specified, send theTERM signal upon timeout. The TERM signal kills any process that does not block or catch that signal. For other processes, it may benecessary to use the KILL (9) signal, since this signal cannot be caught.AUTHORWritten by Padraig Brady.
Example
1
timeout 120
command
If the preceding command is completed within 120 seconds, the system ends safely and is killed after running for more than 120 seconds.
The script is often completed with a dumb breath, so we need to write another script to regularly kill it. With the timeout command, the waist does not hurt, and the legs are not sour. It is healthier to take a rest.
In a word, we don't need to re-engineer the wheel in the script or crontab.
This article is from the "Purple_Grape blog", please be sure to keep this source http://purplegrape.blog.51cto.com/1330104/1302902