我正在远程系统上工作,我使用Pycharm窗口来编辑和运行我的脚本。
我使用
ssh -Y myName@myMachine
然后我从终端机运行Pycharm。
我想以这样的方式从Pycharm运行我的脚本,如果我关闭它(甚至从ssh会话中注销),进程仍然会运行。
我尝试使用“分离而不终止进程”选项退出Pycharm。这将导致python过程显示在以下列表中:
ps -all
但是,它停止了对文件的写入。当py魅力打开时,进程通常每隔几秒钟写一次文件。当它脱离py魅力时,它会显示在进程列表中(在注销和再次登录之后,它在ps -x中显示未知的tty),但是它停止工作,因为它不再将任何输出附加到它通常应该添加的文件中。
是什么引起的?我怎么才能解决这个问题?
发布于 2019-04-05 15:54:11
有几种方法:
tmux
和screen
1. `tmux` - The tmux is a terminal multiplexer that enables a number of terminals to be created, accessed, and controlled from a single screen. A tmux session can be detached from a screen and continue running in the background, then later reattached. Like Screen tool, you can also use tmux to detach from an SSH session without quitting the remote jobs.
安装tmux后,使用命令启动tmux会话:
$ tmux
现在,开始你的任务或工作。然后,在不退出远程作业的情况下,安全地从tmux会话中分离出来,方法是按“CTRL”,然后按"d"。这将分离您的tmux会话,但将使您在该会话中所做的工作在后台运行。这意味着即使您与会话断开连接,所有的遥控器也将运行。
若要列出可用的会话,请运行:
$ tmux ls
您可以使用相应的会话ID重新附加到tmux会话,如下所示:
$ tmux附加-t <会话ID >
有关详细信息,请参阅手册页。
$ man tmux
2. `screen` - The screen tool, a full-screen window manager with VT100/ANSI terminal emulation, allows you to safely detach from the SSH session without exiting the remote job. It will be helpful for those who are working with multiple remote servers.
在远程系统上安装屏幕后,启动屏幕会话:
银幕
屏幕会话现在已经启动。现在运行您想在远程系统上执行的任何作业或任务,然后可以通过按“Ctrl”和“d”退出屏幕会话,在脱离屏幕会话后,您可以从远程系统注销。远程作业将继续在服务器中运行。
若要列出屏幕会话,请运行:
$ screen -ls
您可以使用相应的会话ID重新附加到屏幕会话,如下所示:
$ screen -r <会话ID >
有关详细信息,请参阅手册页。
$ man屏幕
1. `nohup` - stands for **No h**ang**up**, is yet another command line utility to help you run Linux commands even after you’re disconnected from the SSH sessions.
这个用法是绝对容易的。登录到远程系统后,您所要做的就是:
$ nohup < command >&
现在,您可以退出SSH会话。远程作业将继续运行。
要列出正在运行的作业,请运行:
-l $ jobs
有关详细信息,请参阅手册页。
$ man nohup
2. `disown` - Disown, removes the job from the process job list of the system, so the process is shielded from being killed during session disconnection as it won’t receive SIGHUP by the shell when you logout.
登录到远程系统后,使用“&”运行命令:
$< command >&
然后,使用以下方法列出正在运行的作业:
-l $ jobs
然后运行与进程ID不一致的进程,如下所示:
不承认-h < PID >
现在可以断开与服务器的连接。
有关详细信息,请参阅手册页。
$ man nohup
登录到远程系统后的
3. `setsid` - setsid allocates a new process group to the process being executed and hence, the process created is totally in a newly allocated process group and can execute safely without fear of being killed even after session logout.
,运行:
$ setsid < command >
有关详细信息,请参阅手册页。
$ man nohup
https://stackoverflow.com/questions/23093971
复制相似问题