Bash 5.0 包括一个新-f
选项wait
:[1]
j. The `wait' builtin now has a `-f' option, which signfies to wait until the
specified job or process terminates, instead of waiting until it changes
state.
Run Code Online (Sandbox Code Playgroud)
这是什么wait -f $pid
做的,而不是默认wait $pid
?在什么条件下-f
需要选择?
更改描述是准确的,但有些模糊,因为wait
通常被认为是等待进程完成。
尝试这个:
sleep 60&
wait %1
Run Code Online (Sandbox Code Playgroud)
然后在另一个终端,
kill -STOP ${pid}
Run Code Online (Sandbox Code Playgroud)
替换${pid}
为sleep
的 pid(作为将其置于后台时的输出)。wait
将退出,因为作业的状态发生了变化。
与-f
,wait
将等待作业或进程真正终止;上面使用,它不会退出kill -STOP
,并会等待进程恢复 ( kill -CONT
) 并完成运行。
归档时间: |
|
查看次数: |
551 次 |
最近记录: |