等待和睡眠的区别是什么?
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.4男人睡眠说:
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只是在给定的秒数内延迟shell。
Wait使shell等待给定的作业。例如:
workhard &
[1] 27408
workharder &
[2] 27409
wait %1 %2
延迟shell,直到两个子进程都完成
推荐文章
- 使用Bash在每个子目录中执行一个操作
- bash:错误的替换
- 如何在bash中删除字符后的所有文本?
- 如何配置git bash命令行补全?
- Shell脚本:在Shell脚本中执行python程序
- /bin/sh: apt-get:未找到
- 如何检索给定相对的绝对路径
- 如何在shell管道中使用“jq”?
- 如何使用jq从JSON获得键名
- 图形化对?
- 我如何能匹配一个字符串与正则表达式在Bash?
- 为什么cURL返回错误“(23)Failed writing body”?
- 在Unix shell中计算一列数字
- 在bash脚本中否定if条件
- 如何撤消“set -e”使bash立即退出,如果任何命令失败?