Linux jobs --用于显示当前终端关联的后台任务

来源:互联网 发布:人力资源公司源码 编辑:程序博客网 时间:2024/05/17 22:39

用途说明

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]+  3034Running                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 Oct10 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 processkilled

 

0 0
原创粉丝点击