How do I limit the running time of a BASH script

前端 未结 5 1630
慢半拍i
慢半拍i 2020-12-01 14:39

I have a long running BASH script that I am running under CYGWIN on Windows.

I would like to limit the script to run for 30 seconds, and automatically terminate if i

5条回答
  •  既然无缘
    2020-12-01 15:05

    You could run the command as a background job (i.e. with "&"), use the bash variable for "pid of last command run," sleep for the requisite amount of time, then run kill with that pid.

提交回复
热议问题