Linux命令:jobs

显示作业的状态。

2024-12-31 17:38:59

命令行command

概要

jobs [-lnprs] [jobspec ...]
jobs -x command [args]

主要用途

  • 显示作业的状态。
  • 列出活动的作业。
  • 列出停止的作业。

选项

-l  在作业信息中额外的列出PID。
-n  只列出最近一次通知以来状态变更的作业。
-p  只列出PID。
-r  只输出处于运行状态的作业。
-s  只输出处于停止状态的作业。

返回值

返回状态为成功除非给出了非法选项、执行出现错误。

如果使用jobs -x command [args]形式执行,那么返回值为command的退出状态。

例子

[user2@pc] ssh 192.168.1.4
pc@192.168.1.4's password:
# 此时按下ctrl+z使得交互停止。
[1]+  Stopped                 ssh 192.168.1.4

[user2@pc] sleep 60 &
[2] 13338

[user2@pc] jobs
[1]-  Stopped                 ssh 192.168.1.4
[2]   Running                 sleep 60 &

[user2@pc] jobs -l
[1]- 12927 Stopped                 ssh 192.168.1.4
[2]  13338 Running                 sleep 60 &

[user2@pc] jobs -p
12927
13338

[user2@pc] jobs -s
[1]-  Stopped                 ssh 192.168.1.4

[user2@pc] jobs -r
[2]   Running                 sleep 60 &

[user2@pc] kill -9 12927
[2]   Done                    sleep 60

[user2@pc] jobs -n -l
[1]+ 12927 Killed             ssh 192.168.1.4

[user2@pc] jobs -n -l

注意

  1. bash的作业控制命令包括bg fg kill wait disown suspend
  2. 该命令需要set选项monitor处于开启状态时才能执行;查看作业控制状态:输入set -o查看monitor行;执行set -o monitorset -m开启该选项。
  3. 该命令是bash内建命令,相关的帮助信息请查看help命令。

评论

静谧以待,您的评论将是点睛之笔

撰写首个评论,启程你的前端奇妙之旅

is a Wiki for programming enthusiasts and professionals, organizing knowledge on programming.

Connect With Me

I have a fair amount of knowledge of Javascript, Typescript, VueJs, and Nuxt. If you have an interesting idea, either open source or paid let's connect.

Sent Mail
© 2024-2025 © . All rights reserved.