I want to run a python program 1000 times. If successful it returns output in about 90 seconds, else continue to run may be for 4 hours. I want to run a bash script that will run the python program in a loop in such a way that it waits 100 seconds for the script to terminate successfully else kill it.

It must not kill the next instance of the program which may become successful.

I am working in Ubuntu 12.04 lts.

for i in {1..1000..1}
do
    ./myprocess.py
    sleep 100
done

#And then what........?

Please help

有帮助吗?

解决方案

Try timeout command. Your situation is the exact case, this command is designed for.

timeout 100 ./myprocess.py
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top