linux使用超时终止进程(以毫秒为单位) [英] linux kill process using timeout in milliseconds
本文介绍了linux使用超时终止进程(以毫秒为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Linux上经过指定的时间后强制终止程序. 我发现linux中的'timeout'util可以在指定的时间后杀死程序, 但它不接受MILLISECONDS. 即,"TIME TIME ./PROGRAM"在经过了TIME(毫秒不是秒,而是秒)后杀死了PROGRAM. 在Linux SHELL 上发生一些MILLISECONDS之后,是否有办法杀死进程? 任何意见将不胜感激.
I want to force terminate a program after a specified time is elapsed on linux. I found that 'timeout' util in linux can kill a program after a specified time, but it does not accept MILLISECONDS. That is, "timeout TIME ./PROGRAM" kills PROGRAM after TIME elapsed where TIME is not milliseconds but seconds. Is there a way to kill a process after some MILLISECONDS on linux SHELL? Any comments would be appreciated.
推荐答案
您可以执行以下操作:
#!/bin/bash
#execute command in background
<command> &
#get process ID
PROC=$!
#sleep for 10 milliseconds then kill command
(usleep 10000; kill $PROC) &
#bring back the process ID, finish command or kill it
fg $PROC
这篇关于linux使用超时终止进程(以毫秒为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文