Linux基础命令十三:工作管理

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 /etc

4. 把后台暂停的工作恢复到前台执行

命令

fg %工作号

参数

%工作号:%可以省略,但是注意工作号和pid的区别。jobs命令查看到的第一列数字是工作号

练习:恢复[3]

[root@localhost ~]# fg %3
tar -zcf etc.tar.gz /etc
[root@localhost ~]# jobs
[1]-  Stopped                 top
[2]+  Stopped                 top

5. 把后台暂停的工作恢复到后台执行

命令

bg %工作号

注意

后台恢复执行的命令,是不能与前台交互的,否则不能恢复到后台执行

6. 后台命令脱离终端执行

把命令放入后台,只能在当前登录终端执行。一旦退出或者关闭终端,后台程序就会停止

方法

1.把需要后台执行的命令加入/etc/rc.local文件
2.使用系统定时任务,让系统在指定的时间执行某个后台命令
3.使用nohup命令(标准方法)

7. nohup 命令

格式

nohup [命令] &
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值