Set timeout for programs in Centos

Source: Internet
Author: User
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 CentOS6 platform, from the software package coreutils # whichtimeout/usr/bin/timeout # rpm-qf/usr/bin/timeoutcoreutils-8.4-19.el6_4.2.x86_64timeout principle is very simple,

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.