BASH - Check if PID Exists

前端 未结 5 1565
情歌与酒
情歌与酒 2021-02-02 10:43

I want to stall the execution of my BASH script until a process is closed (I have the PID stored in a variable). I\'m thinking

while [PID IS RUNNING]; do
sleep 5         


        
5条回答
  •  星月不相逢
    2021-02-02 11:04

    kill -s 0 $pid will return success if $pid is running, failure otherwise, without actually sending a signal to the process, so you can use that in your if statement directly.

    wait $pid will wait on that process, replacing your whole loop.

提交回复
热议问题