verschil tussen wachten en slapen

Wat is verschil tussen waitEN sleep?


Antwoord 1, Autoriteit 100%

waitWacht op een proces om te voltooien; sleepSlaap voor een bepaald aantal seconden.


Antwoord 2, Autoriteit 32%

Wacht is een bash ingebouwd commando. Van 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.

Slaap is geen ingebouwde commando. Het is een hulpprogramma dat voor een bepaalde tijd vertraging.

De sleepOpdracht kan ondersteunen in verschillende tijdseenheden. GNU COREUTILS 8.4 man sleepZEGT:

   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.

Antwoord 3, Autoriteit 24%

sleepvertraagt de shell gewoon met het opgegeven aantal seconden.

waitlaat de shell wachten op de gegeven taak. bijv.:

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

vertraagt de shell totdat beide subprocessen zijn voltooid

Other episodes