ความแตกต่างระหว่างwaitและsleepคืออะไร?
ความแตกต่างระหว่าง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
ล่าช้าเชลล์จนกว่ากระบวนการย่อยทั้งสองจะเสร็จสิ้น
wait %1 %2หรือwait 27408 27409เพียงแค่waitถ้าไม่มีกระบวนการพื้นหลังอื่น ๆ ในกรณีนี้คุณกำลังพยายามที่จะรอ PID 1 (init) และ PID 2 ([การโยกย้าย / 0] บน Linux ของฉัน) แต่คุณจะได้รับข้อความแสดงข้อผิดพลาดที่ชอบ: และผลตอบแทนที่รหัสทางออก-bash: wait: pid 1 is not a child of this shell 127
wait 60รองาน 60 ถึงจะเสร็จสิ้น