等待和睡眠之间的区别

waitsleep什么区别?

等待一个过程完成; sleep一段时间。

等待是BASH内置命令。 从man bash

  wait [n ...] Wait for each specified process and return its termination sta- tus. Each n may be a process ID or a job specification; if a job spec is given, all processes in that job's pipeline are waited for. If n is not given, all currently active child pro- cesses are waited for, and the return status is zero. If n specifies a non-existent process or job, the return status is 127. Otherwise, the return status is the exit status of the last process or job waited for. 

睡眠不是BASH内置命令。 这是一个实用程序,延迟一段指定的时间。

另见: man sleep

sleep只是延迟壳的给定的秒数。

wait使得shell等待给定的subprocess。 例如:

 workhard & [1] 27408 workharder & [2] 27409 wait %1 %2 

延迟shell直到两个subprocess完成

巴什

等待命令停止脚本执行,直到在后台运行的所有作业都已终止,或者直到作为选项指定的作业编号或进程标识终止

 wait%1 or wait $PID wait ${!} 

等待$ {!}的意思是“等到最后一个后台进程完成”($!是上一个后台进程的PID)

睡觉

在指定的时间内添加延迟。

 sleep NUMBER[SUFFIX] sleep 5 (sleep five seconds) 

尝试这个:

 sleep 10 & wait %1