【问题标题】:How to cancel a SSH connection while a process is running?如何在进程运行时取消 SSH 连接?
【发布时间】:2019-12-09 05:40:46
【问题描述】:

我正在使用ssh 连接到另一台(更快的)计算机,以便在那里运行一些 python 代码。由于我预计它会运行几个小时,所以我想在运行后断开连接,如下所示:

$ ssh user@my-other-computer
$ python file.py &
$ exit 

但是,如果我尝试这样做,我会收到消息:

zsh: you have running jobs.

我尝试使用nohup

$ nohup nice python file.py &

但无济于事。

我怎样才能实现我的目标?

【问题讨论】:

  • 使用nohup命令时是否有(错误)输出?
  • 输出是usage: nohup [--] utility [arguments]
  • 似乎是语法错误。

标签: python ssh nohup nice


【解决方案1】:

我不知道为什么nohup 不起作用(可能是因为nice,它可以在没有nice 命令的情况下工作)但有替代方案:

  • screen 创建一个未绑定到会话的新终端(您可以使用screen -dContr+A 分离屏幕会话,然后使用:detach 并使用screen -r 再次附加到它) .您可以使用 screen python file.py

  • 运行命令
  • tmux 是一个终端多路复用器。它类似于屏幕,但具有更多功能并且速度更快。您可以使用 tmux 打开一个 tmux 会话并在新创建的会话中运行 python file.py。您可以使用Contr+Bdtmux detach-client 进行分离。

  • disown 是一个 shell 命令,不拥有当前 shell 中的所有作业,您可以将其关闭,作业将继续运行。

【讨论】:

    猜你喜欢
    • 2011-11-13
    • 2018-07-28
    • 2014-10-12
    • 2013-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 2021-02-12
    相关资源
    最近更新 更多