一天一条Linux指令-jobs

用途说明

jobs命令用于显示当前终端关联的后台任务情况。

命令后面跟上& 用于将命令在后台执行。

Ctrl+Z用于将当前正在运行的前台进程暂停,变成后台进程。

bg [%n]用于将后台暂停的进程继续运行。

fg [%n]用于将后台执行的进程变成前台进程。

kill %n用于杀掉指定的任务。

 

常用参数

-l      显示进程组ID和作业在运行的目录。
-n     只显示上次显示过的已经停止的或已经退出的作业。
-p     只显示选定作业的进程组的进程ID.

使用示例

示例一

[root@jfht ~]# jobs 
[root@jfht ~]# tail -f job.sh 
#!/bin/sh

date >job.txt

Ctrl+Z 
[1]+  Stopped                 tail -f job.sh
[root@jfht ~]# jobs -l 
[1]+  3034 停止                    tail -f job.sh
[root@jfht ~]# bg 
[1]+ tail -f job.sh &
[root@jfht ~]# jobs -l 
[1]+  3034 Running                 tail -f job.sh &
[root@jfht ~]# kill %1 
[root@jfht ~]# jobs -l 
[1]+  3034 已终止                  tail -f job.sh
[root@jfht ~]# jobs -l 
[root@jfht ~]# tail -f job.sh 
#!/bin/sh

date >job.txt


[1]+  Stopped                 tail -f job.sh
[root@jfht ~]# jobs -l 
[1]+  3306 停止                    tail -f job.sh
[root@jfht ~]# jobs 
[1]+  Stopped                 tail -f job.sh
[root@jfht ~]# fg 
tail -f job.sh

Ctrl+C 
[root@jfht ~]# jobs 
[root@jfht ~]#

示例二

[root@jfht ~]# tail -f job.sh 
#!/bin/sh

date >job.txt


[2]+  Stopped                 tail -f job.sh
[root@jfht ~]# bg 
[2]+ tail -f job.sh &
[root@jfht ~]# exit 
logout
There are stopped jobs. 
[root@jfht ~]# exit 
logout

 

重新连接并登录。

Last login: Sun Oct 10 16:54:10 2010 from 222.70.154.57
[root@jfht ~]# ps -ef|grep tail 
root      6464     1  0 18:40 ?        00:00:00 tail -f job.sh
root      6579  6550  0 18:41 pts/8    00:00:00 grep tail

[root@jfht ~]# killall tail 
[root@jfht ~]# killall tail 
tail: no process killed

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值