Set timeout for the program

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 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)NAME       timeout - run a command with a time limitSYNOPSIS       timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...       timeout [OPTION]DESCRIPTION       Start  COMMAND,  and kill it if still running after NUMBER seconds.  SUFFIX may be ‘s’ for seconds (the default), ‘m’ for minutes, ‘h’       for hours or ‘d’ for days.       Mandatory arguments to long options are mandatory for short options too.       -s, --signal=SIGNAL              specify the signal to be sent on timeout.  SIGNAL may be a name like ‘HUP’ or a number.  See ‘kill -l‘ for a list of signals       --help display this help and exit       --version              output version information and exit       If the command times out, then exit with status 124.  Otherwise, exit with the status of COMMAND.  If no signal is specified, send the       TERM signal upon timeout.  The TERM signal kills any process that does not block or catch that signal.  For other processes, it may be       necessary to use the KILL (9) signal, since this signal cannot be caught.AUTHOR       Written by Padraig Brady.



Example

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.