Kill process after a given time bash?

后端 未结 5 1641
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 03:23

I have a script that tries to make a DB connection using another program and the timeout(2.5min) of the program is to long. I want to add this functionality to the script.

5条回答
  •  长情又很酷
    2021-02-01 03:56

    Do you mean you don't want the error message printed if the process isn't still running? Then you could just redirect stderr: kill $pid 2>/dev/null.

    You could also check whether the process is still running:

    if ps -p $pid >/dev/null; then kill $pid; fi
    

提交回复
热议问题