Linux进程前后台设置

本文仍在更新,非最终版本。。

1. nohup,jobs,bg,fg,&

#
# 将命令放入后台执行,终端关闭后命令也关闭 
<terminal order> &
# 命令放入后台执行,终端关闭后命令不关闭
nohup <terminal order> &
Ctrl+Z
bg
jobs
kill %<number>
# 跨服务器用法
# 此时不能再加& 因为需要输入密码,如果加&会处于空白状态
nohup <terminal order> #后台运行
Ctrl+Z #暂停后台运行的job
bg #将暂停的后台job重新start
jobs #查看正在运行的job
tail -f nohup.out #查看后台运行job的屏幕输出

# 推荐rsync结合使用
screen
nohup -avzu --progress <source_path/files> <destination_path>
tail -f nohup.out #查看后台运行job的屏幕输出

## 2. tmux


## 3. Screen

开启一个Screen

screen

恢复一个Screen

screen -ls
screen -r <number>

杀死screen

如果想杀死一个已经detached的screen会话,可以使用以下命令:

screen -X -S [session # you want to kill] quit
举例如下:

[root@localhost ~]# screen -ls
There are screens on:

    9975.pts-0.localhost    (Detached)
    4588.pts-3.localhost    (Detached)

2 Sockets in /var/run/screen/S-root.

[root@localhost ~]# screen -X -S 4588 quit
[root@localhost ~]# screen -ls
There is a screen on:

    9975.pts-0.localhost    (Detached)

1 Socket in /var/run/screen/S-root.

可以看到,4588会话已经没有了。



参考:
https://www.tecmint.com/keep-remote-ssh-sessions-running-after-disconnection/

https://zhengdl126.iteye.com/blog/1523784

https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/index.html

https://www.jianshu.com/p/82fe7f184b93
Last modification:October 20th, 2019 at 06:04 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment