您现在的位置是:网站首页> 编程资料编程资料
Centos下为程序如何设置超时?Centos下为程序设置超时的方法_RedHat/Centos_操作系统_
2024-02-26
179人已围观
简介 Centos下为程序如何设置超时?Centos下为程序设置超时的方法_RedHat/Centos_操作系统_
timeout 是个奇妙的Linux命令,它可以控制程序运行的时间,这对于我们希望控制程序的运行时间非常有用。
timeout在CentOS 6平台上,从属于软件包coreutils
# which timeout
/usr/bin/timeout
# rpm -qf /usr/bin/timeout
coreutils-8.4-19.el6_4.2.x86_64
timeout的原理很简单,一个简单的计时器,一个kill命令,其中-s 可以跟kill的参数,具体怎么杀,就看它。
man timeout仅仅半页,如下
TIMEOUT(1) User Commands TIMEOUT(1)
NAME
timeout - run a commandwith a timelimit
SYNOPSIS
timeout [OPTION] NUMBER[SUFFIX] COMMAND [ARG]...
timeout [OPTION]
DESCRIPTION
Start 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=SIGNAL
specify 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
--version
output version information and exit
If the commandtimesout, thenexitwith status 124. Otherwise, exitwith 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.
用法举例
1timeout 120 command
上面的command命令如果在120秒内完成,则平安结束,运行超过120秒后将被杀死。
脚本经常是傻乎乎的一口气跑到完,搞得我们需要写另一个脚本定期去杀它。自打有了timeout命令,腰也不疼了,腿也不酸了,跑跑歇歇更健康。
一句话,我们在脚本里或者crontab里就不用再造轮子了。
相关内容
- Centos下如何为进程绑定CPU?Centos下为进程绑定CPU的方法_RedHat/Centos_操作系统_
- Centos下rpm包如何制作?Centos下rpm包制作的方法_RedHat/Centos_操作系统_
- Centos中如何临时禁用用户?Centos中临时禁用用户的方法_RedHat/Centos_操作系统_
- CentOS中文件夹基本操作命令的讲解_RedHat/Centos_操作系统_
- CentOS系统如何添加用户操作日志?CentOS系统添加用户操作日志的方法_RedHat/Centos_操作系统_
- Centos进程状态详解_RedHat/Centos_操作系统_
- CentOS EXT4文件系统的详解_RedHat/Centos_操作系统_
- CentOS系统备份脚本详解_RedHat/Centos_操作系统_
- 迷你世界曙光石粉怎么制作 迷你世界曙光石粉合成方法一览_手机游戏_游戏攻略_
- 迷你世界汽车怎么制作 迷你世界汽车合成方法一览_手机游戏_游戏攻略_
