在计算机技术中,wait
是一个命令,可以暂停当前会话,直至后台进程执行完毕。
用法
其中n是当前正在执行的后台进程的pid,或工作的工作ID。如果没有给定n,命令会等待shell调用的所有工作终止。
wait一般返回最后一个工作的退出状态。如果n所指的工作不存在,或没有工作要等待,它会返回127。
因为wait
需要知道当前shell执行环境的工作表,它通常为shell内建命令。
范例
当脚本后部分要求前部分成功执行,此命令可以让前部分并行执行,以节省时间。
下面是一个例子,使用rsync获取iona上的src/目录,同时更新这个程序所依赖的库,然后组合编译。
#!/usr/bin/env bash
# 使用wait命令的并行更新脚本
# 更新本地副本
rsync iona:src/ . &
# 升级所需的库,或如果出于某种原因失败时,返回1并退出
make -C lib || exit 1
# 等待rsync终止(可能已启动),并完成工作,除非rsync失败
wait && make
等待指定的工作控制id号:
$ ls -R / > /dev/null 2>&1 & # 启动长时间运行的后台进程
[2] 1986
$ wait %2 # 等待2号后台工作终止,然后返回
参见
外部链接
|
---|
| 文件系統 | - cat
- cd
- chmod
- chown
- chgrp
- cksum
- cmp
- cp
- dd
- du
- df
- file
- fsck
- fuser
- ln
- ls
- mkdir
- mount
- mv
- pax(英语:pax (Unix))
- pwd
- rm
- rmdir
- size
- split
- stat
- tee
- touch
- type(英语:type (Unix))
- umask(英语:umask)
|
---|
| 程序 | - at
- bg
- chroot
- cron
- fg
- kill
- killall(英语:killall)
- nice
- pgrep
- pkill(英语:pkill)
- ps
- pstree(英语:pstree)
- time
- top
|
---|
| 用户环境 | |
---|
| 文本编辑 | - awk
- banner(英语:banner (Unix))
- basename
- comm(英语:comm)
- csplit(英语:csplit)
- cut
- diff
- dirname
- ed
- ex
- fmt(英语:fmt)
- fold(英语:fold (Unix))
- head(英语:head (Unix))
- iconv
- join(英语:join (Unix))
- less
- more
- nl(英语:nl (Unix))
- paste(英语:paste (Unix))
- sed
- sort(英语:sort (Unix))
- spell(英语:spell (Unix))
- strings(英语:strings (Unix))
- tail
- tr
- uniq(英语:uniq)
- vi
- wc
- xargs
|
---|
| 壳层内建 | |
---|
| 网络(英语:Network utility) | |
---|
| 查找 | |
---|
| 文档 | - apropos(英语:apropos (Unix))
- help(英语:help (command))
- man
|
---|
| 软件开发 | |
---|
| 杂项 | - bc
- cal
- dc
- expr
- lp(英语:lp (Unix))
- lpr
- sleep
- true和false
- yes
|
---|
| |
|