349

wait和有什么区别sleep

4

3 回答 3

412

wait等待进程完成;sleep睡眠一定的秒数。

于 2012-11-08T20:08:12.540 回答
129

wait 是 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 不是 shell 内置命令。它是一种延迟指定时间量的实用程序。

sleep命令可以支持各种时间单位的等待。GNU coreutils 8.4man 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.
于 2012-11-08T20:09:54.587 回答
96

sleep只是将 shell 延迟给定的秒数。

wait使外壳等待给定的工作。例如:

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

延迟 shell 直到两个子进程都完成

于 2012-11-08T20:10:22.990 回答