Bash运行命令一定时间? [英] Bash Run command for certain time?

查看:64
本文介绍了Bash运行命令一定时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个bash脚本供我使用. 如何在特定时间(例如20秒)内运行命令并终止命令? 我尝试了很多解决方案,但没有任何效果,我还尝试了超时命令,但均未成功.请给我一些解决方案.

I am making a bash script for my use. How can I run a command for certain time, like 20 seconds and terminate command? I tried a lot of solutions but nothing works, I also tried timeout command with no success. Please give me some solution for this.

例如:我想在10秒后在脚本和终端中运行此命令

For example: I want to run this command in script and terminal after 10 sec

some command

推荐答案

以下是一些bash脚本和一个名为timelimit的程序,可以解决您的问题. 被允许运行一段时间后杀死进程时间

Here are some bash scripts and a program called timelimit which may solve your problem. Kill process after it's been allowed to run for some time

我想我找到了一个更好的解决方案.尝试使用超时程序.从手册页: 超时-运行具有时间限制的命令".例如:

I think I found a better solution. Try using the timeout program. From the man page: "timeout - run a command with a time limit". For example:

timeout 5s sleep 10s

它基本上运行您的命令,并在指定的持续时间后将其杀死.

It basically runs your command and after the specified duration it will kill it.

这篇关于Bash运行命令一定时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆