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.

最新文章

  1. C++库(TinyXML)
  2. css部分的复习
  3. wooyun本地数据抓取
  4. WebRTC的学习(二)
  5. javascript密码强度验证!
  6. duilib入门之贴图描述、类html文本描述、动态换肤、Dll插件、资源打包
  7. C#基础及记忆概念
  8. jquery.dragsort实现列表拖曳、排序
  9. Zookeeper集群安装详解
  10. [CSS3 + HTML5] Modernizr
  11. hdu2602 Bone Collector (01背包)
  12. 关于C/C++的四舍五入方向
  13. 为什么C++中声明和定义要分开写
  14. js中的回调函数
  15. 一种DTO的规划方案
  16. zabbix忘记admin登录密码重置密码
  17. 透彻讲解,Java线程的6种状态及切换
  18. Testlink解决大用例导入问题
  19. 教你如何使用云服务器去搭建SS
  20. UNITY2018 真机开启deepprofiling的操作

热门文章

  1. C++中public、protected、private
  2. window.showModalDialog以及window.open用法简介
  3. dede密码忘记 的修改方法
  4. 欧几里德算法gcd及其拓展终极解释
  5. WebApi 4.0 默认方式不支持HttpGet 请求
  6. 2016-12-14jq笔记
  7. LRU 算法简单实现
  8. 变身windows达人,用运行命令直接启动所有应用程序
  9. temp gbk2utf8
  10. Mahout