有什么区别
wait
和 sleep
?
wait
等待一个过程完成;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.
睡眠不是内置命令。这是一个延迟指定时间的实用程序。
sleep
命令可以支持以各种时间单位等待。GNU Coreutils 8.4 man sleep
说:
SYNOPSIS
sleep NUMBER[SUFFIX]...
DESCRIPTION
Pause for NUMBER seconds. SUFFIX may be ‘s’ for seconds (the default),
‘m’ for minutes, ‘h’ for hours or ‘d’ for days. Unlike most implemen-
tations that require NUMBER be an integer, here NUMBER may be an arbi-
trary floating point number. Given two or more arguments, pause for
the amount of time specified by the sum of their values.
sleep
只是延迟了给定数量的秒数。
wait
使外壳等待给定的作业。例如:
workhard &
[1] 27408
workharder &
[2] 27409
wait %1 %2
延迟外壳,直到两个子过程都完成