search

Home  >  Q&A  >  body text

linux - ssh连接断开后怎么保证进程不死

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

阿神阿神2864 days ago1405

reply all(14)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 11:09:25

    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.

    reply
    0
  • 黄舟

    黄舟2017-04-17 11:09:25

    What lz needs is tmux or screen

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 11:09:25

    Try nohup

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

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

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 11:09:25

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

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 11:09:25

    Add &

    at the end of the script

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 11:09:25

    Find something to hold down the keyboard. . .

    reply
    0
  • 阿神

    阿神2017-04-17 11:09:25

    tmux or screen

    byobu is just a beautified wrapper for tmux/screen

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 11:09:25

    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

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 11:09:25

    byobu you deserve it! Easier to use than screen

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 11:09:25

    setsid - run a program in a new session

    reply
    0
  • Cancelreply