bash 等待和睡眠的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13296863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between wait and sleep
提问by ziiweb
What is difference between wait
and sleep
?
wait
和 和有什么区别sleep
?
回答by MRAB
wait
waits for a process to finish; sleep
sleeps for a certain amount of seconds.
wait
等待一个进程完成;sleep
睡眠一定的秒数。
回答by kbulgrien
wait is a BASH built-in command. From man bash
:
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 is not a shell built-in command. It is a utility that delays for a specified amount of time.
sleep 不是 shell 内置命令。它是一种延迟指定时间量的实用程序。
The sleep
command may support waiting in various units of time. GNU coreutils 8.4 man sleep
says:
该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.
回答by pbhd
sleep
just delays the shell for the given amount of seconds.
sleep
只是将外壳延迟给定的秒数。
wait
makes the shell wait for the given job. e.g.:
wait
使外壳等待给定的作业。例如:
workhard &
[1] 27408
workharder &
[2] 27409
wait %1 %2
delays the shell until both of the subprocesses have finished
延迟 shell 直到两个子进程都完成