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. codeforces 1037

    题解: E-trips 哎哎哎好傻逼啊 没有想到算不能的一直在想怎么算能的 太傻逼了 其实很简单 我们只需要对好友<=k的首先dfs一下给他连接着的朋友-1 然后如果小于了就递归下去 这个正确性 ...

  2. bzoj2908

    题解: 我的做法好像跟网上不太一样.. 首先分位讨论 我的做法是先观察出了一个性质 这个答案只跟最后一个0出现的位置有关(这个随便yy一下很容易出来因为运算有0则1) 然后问题就变成了 给出一棵树,支 ...

  3. nginx做代理安装docker

    1.环境 服务器IP 服务用途 是否能 联网 192.168.126.128 docker服务器(简称B服务器) 不能 192.168.126.130 nginx服务器(简称A服务器) 能 2.背景 ...

  4. fanuc 机床,加工中心通信总结,机床联网监控系统

    有需求要与fanuc机床及加工中心通讯,读取状态信息. 1.通过了解,与fanuc通讯需要具备的硬件条件如下: a.串口通讯:可以进行程序的上传下载,绝大部分机床状态也是以文件的形式保存,所以理论上都 ...

  5. 谈谈Nginx-HTTPS加密技术

    超文本传输安全协议(HTTPS)是以安全为目标的HTTP通道,简单来说就是HTTP安全版.https由两个部分组成:HTTP+SSL/TLS,在http基础上加上了一层加密信息模块,服务端和客户端的信 ...

  6. 给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。

    示例 1: 输入: [1,2,3,4,5,6,7] 和 k = 3 输出: [5,6,7,1,2,3,4] 解释: 向右旋转 1 步: [7,1,2,3,4,5,6] 向右旋转 2 步: [6,7,1 ...

  7. SSH框架学习------struts2(一)

    1.总的目录 2.所有程序 1)index.jsp很简单 <%@ page language="java" contentType="text/html; char ...

  8. Python3.4+Django1.9+Bootstrap3

    实现和原理 Python集成Django开发框架后,可以通过在cmd命令提示符下建立工程,工程名为learn_models 1 django-admin.py startproject learn_m ...

  9. PAT (Advanced Level) Practise 1002 解题报告

    GitHub markdownPDF 问题描述 解题思路 代码 提交记录 问题描述 A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 ...

  10. nginx那些事儿

    一.mac上安装nginx brew install nginx # 核心安装目录,启动文件在该目录的bin下面,欢迎页面在html下面. /usr/local/Cellar/nginx/1.12.2 ...