1、 Linux下从一个终端获取另一个终端正在运行的程序的输出内容的方法:
reptyr <PID>
具体安装:
使用reptyr
Ubuntu下,直接sudo apt-get install reptyr安装即可
使用方法就是
reptyr <PID>
比如你需要获取的程序PID为7191,那么需要执行的命令就是
reptyr 7191
如果出现这种情况
[-] Process 4118 (python) shares 7191's process group. Unable to attach.
(This most commonly means that 7191 has suprocesses).
Unable to attach to pid 7191: Invalid argument
如下图
直接在命令后面添加参数 -T 然后使用管理员权限运行即可
sudo reptyr 7191 -T
2、Linux后台运行python程序并输出日志
现在有test.py程序要后台部署, 里面有输出内容
nohup python -u test.py > test.log 2>&1 &
最后的&表示后台运行
2 输出错误信息到提示符窗口
1 表示输出信息到提示符窗口, 1前面的&注意添加, 否则还会创建一个名为1的文件
tail -f test.log如果要实时查看日志文件使用命令
cat test.log查看全部输出使用命令
其他
Linux nohup和&后台运行,进程查看及终止,进程信息输出,控制台信息输出
nohup和&后台运行,进程查看及终止
https://www.cnblogs.com/cfas/p/9348880.html