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. NSFileManager和NSFileHandler的作用, category的理解

    NSFileManager类可以管理文件系统中的文件和目录,也可以定位.判断是否存在.创建.拷贝.删除文件和目录,还可以获得文件和目录的信息: 对于读写文件,NSFileManager只可以读写字符串 ...

  2. memcached 配置

    Memcached是一款开源.高性能.分布式内存对象缓存系统,可应用各种需要缓存的场景,其主要目的是通过降低对Database的访问来加速web应用程序.它是一个基于内存的“键值对”存储,用于存储数据 ...

  3. HDU2732 Leapin' Lizards 网络流 最大流 SAP

    原文链接http://www.cnblogs.com/zhouzhendong/p/8362002.html 题目传送门 - HDU2732 题意概括 给你一个网格,网格上的一些位置上有一只蜥蜴,所有 ...

  4. 在github上创建新的分支(包括管理分支)

    考虑到前面的项目在master分支上,这个不是太友好,下面在只有master分支的基础上,新建一个dev分支 一:查看 1.查看本地分支 git branch 2.查看远程分支 git branch ...

  5. css图片根据div宽高比例自适应

    1.div布局 <div class="card-img-show"> <div class="upload-img-conss" > ...

  6. Centos7 安装PhantomJS

    1.下载地址:http://phantomjs.org/download.html 2.文件名:phantomjs-2.1.1-linux-x86_64.tar.bz2   # 下载好后进行解压(由于 ...

  7. 给力的移动 FZU - 2287

    你的弟弟给你安排了一个任务,他给了你1到N个数字的乱序排列,现在你想给你的弟弟秀一波操作,操作最少的次数把序列变成1到N的顺序排列,每次操作你可以选择序列中的一个数字并把它移动到序列的头部或尾部. I ...

  8. Java内存管理-掌握类加载器的核心源码和设计模式(六)

    勿在流沙筑高台,出来混迟早要还的. 做一个积极的人 编码.改bug.提升自己 我有一个乐园,面向编程,春暖花开! 上一篇文章介绍了类加载器分类以及类加载器的双亲委派模型,让我们能够从整体上对类加载器有 ...

  9. Fenng对于管理技术团队的思考

    丁香园CTO冯大辉谈技术团队管理 http://www.infoq.com/cn/interviews/fdh-team-manager http://www.geekpark.net/topics/ ...

  10. skatebroads

    skateboardsn.滑板( skateboard的名词复数 ) == skateboard英 [ˈskeɪtbɔ:d]  . 斯给特博得. 美 [ˈskeɪtbɔ:rd] n.滑板复数: ska ...