1. 概述
指在单个登录终端中同时管理多个工作的行为,即后台管理2. 查看后台任务命令
命令
jobs [选项]选项
-l:显示工作的pid注意
+号代表最近一个放入后台的工作,也是工作恢复时,默认恢复的工作。 -号代表倒数第二个放入后台的工作3. 把进程放入后台
&:放入后台执行(执行) 或 按Ctrl+z快捷键,放在后台暂停(暂停)练习1:top &
[root@localhost ~]# top & [1] 16321 [root@localhost ~]# jobs [1]+ Stopped top练习1:top Ctrl+Z
[root@localhost ~]# top 按Ctrl+Z [root@localhost ~]# jobs [1]- Stopped top [2]+ Stopped top [root@localhost ~]# jobs -l [1]- 16321 Stopped (signal) top [2]+ 16336 Stopped (signal) top练习2:tar&
[root@localhost ~]# tar -zcf etc.tar.gz /etc & [3] 16485 [root@localhost ~]# tar: Removing leading `/' from member names jobs [1]- Stopped top [2]+ Stopped top [3] Done tar -zcf etc.tar.gz /etc练习2:tar Ctrl+Z
[root@localhost ~]# tar -zcf etc.tar.gz /etc tar: Removing leading `/' from member names ^Z [3]+ Stopped tar -zcf etc.tar.gz /etc [root@localhost ~]# jobs [1] Stopped top [2]- Stopped top [3]+ Stopped tar -zcf etc.tar.gz /etc4. 把后台暂停的工作恢复到前台执行
命令
fg %工作号参数
%工作号:%可以省略,但是注意工作号和pid的区别。jobs命令查看到的第一列数字是工作号练习:恢复[3]
[root@localhost ~]# fg %3 tar -zcf etc.tar.gz /etc [root@localhost ~]# jobs [1]- Stopped top [2]+ Stopped top5. 把后台暂停的工作恢复到后台执行
命令
bg %工作号注意
后台恢复执行的命令,是不能与前台交互的,否则不能恢复到后台执行6. 后台命令脱离终端执行
把命令放入后台,只能在当前登录终端执行。一旦退出或者关闭终端,后台程序就会停止方法
1.把需要后台执行的命令加入/etc/rc.local文件 2.使用系统定时任务,让系统在指定的时间执行某个后台命令 3.使用nohup命令(标准方法)7. nohup 命令
格式
nohup [命令] &