Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
517 views
in Technique[技术] by (71.8m points)

timeout - Bash Run command for certain time?

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.

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

some command
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

EDIT: 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...