码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 笔记 #05# 断开远程连接后保持程序运行

时间:2018-03-04 16:08:34      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:tcp   blank   strong   -o   hat   min   安装   http   ref   

教程:Linux 技巧:让进程在后台可靠运行的几种方法

网上搜索了一下,方法很多,选用最流行的 screen

命令参考:http://man.linuxde.net/screen 

 

1. 安装

root@xkfx:~# apt install screen

...

root@xkfx:~# screen -list 列出所有会话
There is a screen on:
        1883.pts-0.xkfx (03/04/2018 12:06:15 PM)        (Attached)
1 Socket in /var/run/screen/S-root.

 

2. 基本操作

例如说我现在打算关机(断开 ssh)睡午觉,又希望挖矿程序继续运行:

root@xkfx:~# screen -ls
There is a screen on:
1883.pts-0.xkfx (03/04/2018 12:06:14 PM) (Detached)
1 Socket in /var/run/screen/S-root.

root@xkfx:~# screen -dmS MyWorker
root@xkfx:~# screen -ls
There are screens on:
2210.MyWorker (03/04/2018 12:38:55 PM) (Detached)
1883.pts-0.xkfx (03/04/2018 12:06:15 PM) (Detached)
2 Sockets in /var/run/screen/S-root.

root@xkfx:~# screen -r 2227.MyWorker 

(screen -r 2227 或者 screen -r MyWorker 均可)

root@xkfx:/# screen -ls
There are screens on:
2227.MyWorker (03/04/2018 12:40:00 PM) (Attached)
1883.pts-0.xkfx (03/04/2018 12:06:15 PM) (Detached)
2 Sockets in /var/run/screen/S-root.

root@xkfx:/# cd /opt/antpool/cpuminer-2.5.0/
root@xkfx:/opt/antpool/cpuminer-2.5.0# ./minerd -o stratum+tcp://stratum-ltc.antpool.com:8888 -u xkfx.01
[2018-03-04 12:45:10] 1 miner threads started, using ‘scrypt‘ algorithm.
[2018-03-04 12:45:10] Starting Stratum on stratum+tcp://stratum-ltc.antpool.com:8888
[2018-03-04 12:45:12] thread 0: 4104 hashes, 15.34 khash/s

[detached from 2227.MyWorker]

(这里的操作是 Ctrl + A + D)

root@xkfx:~# screen -ls
There are screens on:
2227.MyWorker (03/04/2018 12:40:00 PM) (Detached)
1883.pts-0.xkfx (03/04/2018 12:06:15 PM) (Detached)
2 Sockets in /var/run/screen/S-root.

好了,现在可以关机睡午睡了。

醒来后想看看程序是不是仍在运行:

root@xkfx:~# screen -ls
There are screens on:
2227.MyWorker (03/04/2018 12:39:59 PM) (Detached)
1883.pts-0.xkfx (03/04/2018 12:06:14 PM) (Detached)
2 Sockets in /var/run/screen/S-root.

root@xkfx:~# screen -r 2227.MyWorker

[2018-03-04 13:26:38] accepted: 28/28 (100.00%), 15.55 khash/s (yay!!!)
[2018-03-04 13:27:38] thread 0: 932832 hashes, 15.55 khash/s
[2018-03-04 13:27:39] thread 0: 9480 hashes, 15.58 khash/s
[2018-03-04 13:27:39] accepted: 29/29 (100.00%), 15.58 khash/s (yay!!!)
[2018-03-04 13:28:14] thread 0: 539904 hashes, 15.55 khash/s
[2018-03-04 13:28:14] accepted: 30/30 (100.00%), 15.55 khash/s (yay!!!)

 

3. 应用

解决一下上次的遗留问题

root@xkfx:~# screen -dmS myChatroomServer

root@xkfx:~# screen -r myChatroomServer

root@xkfx:~# java -jar main.jar
The server is listening on 10000 port ...

[detached from 2586.myChatroomServer]

操作完后断开 ssh 测试:

技术分享图片

 

ps:终结一个 screen ,切入该 screen , Ctrl + D

Linux 笔记 #05# 断开远程连接后保持程序运行

标签:tcp   blank   strong   -o   hat   min   安装   http   ref   

原文地址:https://www.cnblogs.com/xkxf/p/8504302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!