IT

대기와 수면의 차이점

lottoking 2020. 3. 25. 08:36
반응형

대기와 수면의 차이점


차이 무엇 waitsleep?


wait프로세스가 완료되기를 기다립니다. sleep특정 시간 (초) 동안 대기합니다.


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은 쉘 내장 명령이 아닙니다. 지정된 시간 동안 지연되는 유틸리티입니다.

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

두 서브 프로세스가 완료 될 때까지 쉘을 지연시킵니다.


세게 때리다

백그라운드에서 실행중인 모든 작업이 종료되거나 옵션으로 지정된 작업 번호 또는 프로세스 ID가 종료 될 때까지 대기 명령이 스크립트 실행을 중지합니다.

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

wait $ {!}는 "마지막 백그라운드 프로세스가 완료 될 때까지 기다립니다"($!는 마지막 백그라운드 프로세스의 PID 임)를 의미합니다.

자다

지정된 시간 동안 지연을 추가하십시오.

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

이 시도:

sleep 10 &
wait %1

참고 URL : https://stackoverflow.com/questions/13296863/difference-between-wait-and-sleep

반응형