Managing Shell Jobs  

When moving jobs between the foreground and background, it may be useful to have an overview of all current jobs. To get such an overview, use the  jobs command. As you can see in  Table   9.2   , this command gives an overview of all jobs currently running as a background job, including the job number assigned to the job when starting it in the background. These job numbers can be used as an argument to the  fg  and  bg  commands to perform job management tasks. In  Exercise 9.1 , you learn how to perform common job management tasks from the shell.

一个很好的练习Jobs管理的实例:

Exercise 9.1 Managing jobs In this exercise, you apply the commands that you just learned about to manage jobs that have been started from the current shell.

1. Open a root shell and type the following commands:

sleep 3600 &
dd if=/dev/zero of=/dev/null &
sleep 7200

2. Because you started the last command with no & after the command, you have to wait 2 hours before you get control to the shell back. Type Ctrl+Z to stop it.

3. Type jobs . You will see the three jobs that you just started. The first two of them have the Running state, and the last job currently is in the Stopped state.

[root@rhel7 ~]# sleep  &
[]
[root@rhel7 ~]# dd if=/dev/zero of=/dev/null &
[]

 [root@rhel7 ~]# sleep 7200
 ^Z
 [3]+ Stopped sleep 7200
 [root@rhel7 ~]# jobs
  [1] Running sleep 3600 &
  [2]- Running dd if=/dev/zero of=/dev/null &
  [3]+ Stopped sleep 7200

4. Type bg 3 to continue running job 3 in the background. Notice that because it was started as the last job, you did not really have to add the number 3.

[root@rhel7 ~]# bg
[]+ sleep &
[root@rhel7 ~]# jobs
[] Running sleep &
[]- Running dd if=/dev/zero of=/dev/null &
[]+ Running sleep &
[root@rhel7 ~]#

5. Type fg 1 to move job 1 to the foreground.

6. Type Ctrl+C to cancel job number 1 and use jobs to confirm that it is now gone.

7. Use the same approach to cancel jobs 2 and 3 also.

[root@rhel7 ~]# fg
sleep
^C
[root@rhel7 ~]# jobs
[]- Running dd if=/dev/zero of=/dev/null &
[]+ Running sleep &
[root@rhel7 ~]# fg
dd if=/dev/zero of=/dev/null
^C590233206+ records in
+ records out
bytes ( GB) copied, 372.251 s, MB/s [root@rhel7 ~]# jobs
[]+ Running sleep &
[root@rhel7 ~]# fg
sleep
^C
[root@rhel7 ~]# jobs
[root@rhel7 ~]#

8. Open a second terminal on your server.

9. From that second terminal, type dd if=/dev/zero of=/dev/null & .

10. Type exit to close the second terminal.

11. From the other terminal, start top . You will see that the dd job is still running. From top, use k to kill the dd job.

Managing linux Shell Jobs的更多相关文章

  1. linux —— shell 编程(文本处理)

    导读 本文为博文linux —— shell 编程(整体框架与基础笔记)的第4小点的拓展.(本文所有语句的测试均在 Ubuntu 16.04 LTS 上进行) 目录 基本文本处理 流编辑器sed aw ...

  2. linux —— shell 编程(整体框架与基础笔记)

    导读 关于shell编程基础的学习,网上有很多资源,如果在校图书馆应该也有一些教程,所以这里对于零碎的基础不做详细记录,而只是对一些常用的概念.命令与操作做一个简要的记录,以备方便查找. (本文所有语 ...

  3. Linux Shell基础(下)

    Linux Shell基础(下) 目录 一.shell特殊符号cut命令 二.cut.sort.wc.uniq命令 三.tee.tr.split命令 四.简易审计系统 五.fork, exec, so ...

  4. Linux shell基础知识(上)

    Linux shell基础知识(上) 目录 一.shell介绍 二.命令历史 三.命令补全和别名 四.通配符 五.输入输出重定向 六.管道符和作业控制 七.shell变量 八.环境变量配置文件 九.b ...

  5. Linux Shell脚本编程while语句案例

    1,每隔3秒,打印一次系统负载 #!/bin/bash while true do uptime done 2,把监控结果保存到文件,在后台执行,然后用tail -f监控文件变化 ghostwu@de ...

  6. Linux shell下30个有趣的命令

    Tips 原文作者:Víctor López Ferrando 原文地址:30 interesting commands for the Linux shell 这些是我收集了多年的Linux she ...

  7. LINUX任务(jobs)详解

    LINUX任务(jobs)详解 在用管理员执行一个命令后,用Ctrl+Z把命令转移到了后台.导致无法退出root的. 输入命令:exit终端显示:There are stopped jobs. 解决方 ...

  8. Linux Shell编程与编辑器使用详解

    <Linux Shell编程与编辑器使用详解> 基本信息 作者: 刘丽霞 杨宇 出版社:电子工业出版社 ISBN:9787121207174 上架时间:2013-7-22 出版日期:201 ...

  9. [转]Linux shell中的那些小把戏

    我日常使用Linux shell(Bash),但是我经常忘记一些有用的命令或者shell技巧.是的,我能记住一些命令,但是肯定不会只在特定的任务上使用一次,所以我就开始在我的Dropbox账号里用文本 ...

随机推荐

  1. 记一次npapi插件无窗口(windowless )化下的妙巧思路然后解决问题的超爽体验过程

     1:问题 集成第三方的ocx控件,用来做pdf显示和签名.如果用窗口化插件做,很简单,加载ocx到窗口中,再显示到网页即可.但这样有个缺点.就是这个窗口会浮动在网页元素的上面,导致遮挡住网页元素.比 ...

  2. C++工厂方法模式

    class IFactoryBase { public: IFactoryBase(void); virtual ~IFactoryBase(void); public: virtual IProdu ...

  3. 【USACO 2.3.1】最长前缀

    [题目描述] 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当 ...

  4. Mysql 应该选择什么引擎

    对于如何选择存储引擎,可以简答的归纳为一句话:“除非需要用到某些INNODB 不具备的特性,并且没有其他办法可以替代,否则都应该选择INNODB 引擎”.例如:如果要用到全文索引,建议优先考虑INNO ...

  5. Jquery练手之-贪吃蛇

    记得以前刚出来工作的时候,什么都不懂.老板让用Jquery写一个功能,我不会写,然后跟老板说,我就是个.net程序员,为什么要写Jquery...后面我们老大给我写了!现在我才知道net程序员要会多少 ...

  6. Yii 框架里数据库操作详解

    增:1 第一种 $post=new Post; $post->title='sample post'; $post->content='content for the sample pos ...

  7. jQuery图片提示示例

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. HDU 1312:Red and Black(DFS搜索)

      HDU 1312:Red and Black Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  9. Dapper快速学习

    Dapper快速学习 我们都知道ORM全称叫做Object Relationship Mapper,也就是可以用object来map我们的db,而且市面上的orm框架有很多,其中有一个框架 叫做dap ...

  10. 粗看C#委托

    C#的好多定义跟C艹不太相同,先来分析一下“委托”. 1. 委托的定义: 委托,可以认为是类型安全的函数指针,类型安全就是指明确定义了返回类型与参数类型,在C#代码编译时就能够确保指针传参时的安全性. ...