http://www.digitalinternals.com/unix/unix-linux-run-command-with-timeout/500/

There are two ways to send a SIGKILL signal to the process from the timeout utility. The first way is by specifying the default signal to be sent using the following syntax.

$ timeout -s KILL 1m /path/to/slow-command arg1 arg2

The second way is to first send the SIGTERM after the initial timeout. Then, wait for another timeout and send a SIGKILL to the process if it’s still running. This can be done using the following syntax.

$ timeout -k 30 1m /path/to/slow-command arg1 arg2

The process is sent a SIGTERM signal after 60 seconds. If it is still running, then a SIGKILL signal is sent after another 30 seconds.

In the event that the timeout utility is not available, the below 1-liner can be used as an alternative.

$ /path/to/slow-command arg1 arg2 & sleep 60; kill $!

The slow-command is started as a background process. The sleep command will then pause till the timeout duration. In our case, it will sleep for 60 seconds. Once 60 seconds has elapsed, the kill command will send a SIGTERM signal to the slow-command process. The ‘$!‘ shell variable will give the PID of the last background job.

linux bash timeout的更多相关文章

  1. 转: windows 10使用原生linux bash命令行

    转: https://www.zybuluo.com/pandait/note/337430 windows 10使用原生linux bash命令行 linux bash windows-10 第一时 ...

  2. Linux Bash代码 利用for循环实现命令的多次执行

    Linux Bash代码 [yuanhao15@lu01 libsvm-rank-2.81]$ for ((i=0; i<=19; i++)) do ./svm-train -s 5 -c 10 ...

  3. linux BASH shell设置字体与背景颜色

    linux BASH shell下设置字体及背景颜色的方法. BASH shell下设置字体及背景颜色  echo -e "\e[31mtest\e[41m"  \e[30m 将字 ...

  4. Linux:-bash: ***: command not found

    Linux:-bash: ***: command not found,系统很多命令都用不了,均提示没有此命令. 突然之间linux很多命令都用不了,均提示没有此命令. 这应该是系统环境变量出现了问题 ...

  5. Linux Bash命令关于程序调试详解

    转载:http://os.51cto.com/art/201006/207230.htm 参考:<Linux shell 脚本攻略>Page22-23 Linux bash程序在程序员的使 ...

  6. 禁用Linux bash rm --force

    防止无意的Linux bash rm --force 二.禁用rm -rf 因为rm -rf 删除文件的时候,经常会不小心将系统文件或者多个有用的目录删除掉.有两种方法:1,每次删除都用-i(inte ...

  7. linux bash关闭标准输出1(exec 1<&-)后重新打开

    linux bash shell的再次学习. 文件描述符: stdin,stdout 和 stderr 的文件描述符分别是 0,1 和 2(一个文件描述符说白了就是文件系统为了跟踪这个打开的文件而分配 ...

  8. win10开启 linux Bash命令(win10内置了linux系统支持)

    win10开启 Ubuntu linux Bash命令(win10内置了linux系统支持) 第一步: 先在设置→更新和安全→针对开发人员中选择"开发人员模式",点击后会下载&qu ...

  9. 【Linux】linux bash shell之变量替换::=句法、=句法、:-句法、-句法、=?句法、?句法、:+句法、+句法

    linux bash shell之变量替换::=句法.=句法.:-句法.-句法.=?句法.?句法.:+句法.+句法   linux bash shell之变量替换::=句法.=句法.:-句法.-句法. ...

随机推荐

  1. 在vs.net 2010,2015 等版本,给JS函数添加代码提示\注释

    经常编写JS的朋友常常会因为函数写多了,隔一段时间就会忘记了函数的用途,或者函数里带的参数作用情况,这个时候会联想到VS工具里的强大提示功能,多希望也能在JS上实现呀,告诉你,这个想法并不是多难,VS ...

  2. 【Android】 textview 中超出屏幕宽度的字符 省略号显示

    当利用textview显示内容时,显示内容过多可能会折行或显示不全,那样效果很不好. 实现如下: <TextView android:layout_width="fill_parent ...

  3. Centos6.5安装Apache ab性能测试工具

    ab简洁: ab是apache自带的压力测试工具,ab是apachebench命令的缩写. ab不仅可以对apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试. ab是一个h ...

  4. Flask---第二个例子--Get和POST发送

    *get:浏览器告诉服务器,我只需要获取页面信息给我,这是最简单最常用的方法 *Post:览器告诉服务器:想在 URL 上 发布 新信息.并且,服务器必须确保 数据已存储且仅存储一次.这是 HTML ...

  5. js中的new Option默认选中

    new Option("文本","值",true,true).后面两个true分别表示默认被选中和有效! //js默认选中 var sel = document ...

  6. OpenSSL-Win64创建IdentityServer证书

    d:cd xx C:\OpenSSL-Win64\bin\openssl req -newkey rsa:2048 -nodes -keyout identity.key -x509 -days 36 ...

  7. VS2017 下载离线MSDN文档

    VS2017 下载离线MSDN文档 点开帮助窗口的时候发现没有添加和删除帮助内容选项.处理方法如下: 1.打开vs2017安装包,如果你找不到安装包,可在相应你下载vs2017的浏览器上找到下载内容, ...

  8. Django2.0引入css、js、img文件

    Django2.0引入css.js.img文件 一.文件结构 二.settings.py的配置 # Static files (CSS, JavaScript, Images) # https://d ...

  9. react+typescript报错集锦<持续更新>

    typescript报错集锦 错误:Import sources within a group must be alphabetized.tslint(ordered-imports) 原因:impo ...

  10. 橡皮筋进度条ElasticProgressBar

    橡皮筋进度条ElasticProgressBar 橡皮筋进度条是一个极具动画效果的进度条.该进度条不仅具有皮筋效果,还带有进度数据显示,让用户可以很清晰的看到当前的进度,可用于下载.加载进度等场景.E ...