linux - ssh连接断开后怎么保证进程不死
阿神
阿神 2017-04-17 11:07:25
0
14
1352

我经常有这样的需求,通过ssh连接到服务器上,运行一个脚本。
因为脚本要运行很久,所以就丢在那里,看着打印输出。
一会儿不管他,电脑就进入休眠了,网络也就断了,ssh就断了,服务器运行的进程也挂了。
有没有什么办法,可以让这种情况下进程不死,然后再次练上去还可以继续看脚本运行的打印

阿神
阿神

闭关修行中......

reply all(14)
巴扎黑

Ready to run
nohup xxx &

If already running
ctrl z pause
jobs See the id of the suspended task
bg id
disown id #Note: Without this sentence, the process will receive SIGHUP when the terminal ends. The default operation corresponding to this signal is to end the process

In addition to nohup, you can also use setsid, but the best thing is to use something like screen.

黄舟

What lz needs is tmux or screen

大家讲道理

Try nohup

nohup - run a command immune to hangups, with output to a non-tty

http://www.21andy.com/blog/20071121/6...

巴扎黑

Install a screen
See: http://www.ibm.com/developerworks/cn/...

小葫芦

Add &

at the end of the script
小葫芦

Find something to hold down the keyboard. . .

阿神

tmux or screen

byobu is just a beautified wrapper for tmux/screen

洪涛

This is because ssh has a time limit. If the client does not respond within a period of time, the server will disconnect.
Add
to /etc/ssh/ssh_config ServerAliveInterval 60
One line and that’s it

巴扎黑

byobu you deserve it! Easier to use than screen

大家讲道理

setsid - run a program in a new session

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template