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 次 |
| 最近记录: |