对服务器中的进程进行管理

查看当前在后台执行的命令

[root@iZ23e5fkkhxZ ~]# jobs 
[1]+  Stopped                 vim aaa

让任务在后台运行

[root@iZ23e5fkkhxZ ~]# bg %1
[1]+ vim aaa &

把后台的任务拿到前台来运行

[root@iZ23e5fkkhxZ ~]# bg %1
[1]+ vim aaa &

把命令放到后台执行,可以使用&符号,但是单纯使用这个命令的话,在当前会话链接结束之后,这个命令的执行也会结束

[root@iZ23e5fkkhxZ ~]# ls &
[1] 30847

在命令执行的时候Ctrl + z可以把命令的执行放在后台,但是任务是停止的状态

nohup 命令和 & 符号的结合使用可以使命令在后台执行,并且不会受当前回话断开的影响

[root@iZ23e5fkkhxZ ~]# nohup grep -lr jin /home/xx.xxx.xxx/public_html &
[1] 30969
[root@iZ23e5fkkhxZ ~]# nohup: ignoring input and appending output to `nohup.out'

使用screen命令,screen命令需要单独安装

# 输入screen命令进入screen
[root@iZ23e5fkkhxZ ~]# screen
# 执行需要的命令
[root@iZ23e5fkkhxZ ~]# grep -lr jin /home/xx.xxx.xxx/public_html &
# Ctrl + a 然后加d,就可以保存当前的screen
[detached]
# 查看后台的screen的信息
[root@iZ23e5fkkhxZ ~]# screen -ls
There is a screen on:
    31371.pts-3.iZ23e5fkkhxZ    (Detached)
1 Socket in /var/run/screen/S-jtcm.
# 回到screen
[root@iZ23e5fkkhxZ ~]# screen -r 31371

标签: linux

添加新评论