#Bash 的 jobs 命令
jobs [OPTION]... [JOBSPEC]...
功能
查看作业状态。
类型
Bash 内置命令。
参数
OPTION选项:-l- 显示进程 ID-n- 仅显示(自上次通知以来)状态发生改变的进程-p- 只显示进程 ID-r- 只显示正在运行的作业-s- 只显示暂停的作业-x CMD [ARG]...- 执行命令;ARG中可以使用以下特殊参数%1- 第一个作业的进程 ID,以此类推%+- 当前作业(最后一个暂停的作业)的进程 ID%-- 上一个作业(最后一个后台作业)的进程 ID
#示例
查看作业
$ jobs # 查看作业
[1]+ Stopped sleep 100
[2] Running sleep 100 &
[3]- Running sleep 200 &
操作作业
$ jobs
[1]- Running sleep 100 &
[2]+ Running sleep 200 &
$ jobs -x kill %1 %2 # 杀死 1,2 号作业
$ jobs # 查看
[1]- Terminated sleep 100
[2]+ Terminated sleep 200
#相关命令
#推荐阅读
#手册
jobs: jobs [-lnprs] [jobspec ...] or jobs -x command [args]
Display status of jobs.
Lists the active jobs. JOBSPEC restricts output to that job.
Without options, the status of all active jobs is displayed.
Options:
-l lists process IDs in addition to the normal information
-n lists only processes that have changed status since the last
notification
-p lists process IDs only
-r restrict output to running jobs
-s restrict output to stopped jobs
If -x is supplied, COMMAND is run after all job specifications that
appear in ARGS have been replaced with the process ID of that job's
process group leader.
Exit Status:
Returns success unless an invalid option is given or an error occurs.
If -x is used, returns the exit status of COMMAND.