U2r*_*ros 24 python command-line services
我有一个基于 python 的服务器,我从终端开始。终端的这个特定实例然后将控制权交给程序,程序将其用作一种日志记录窗口,直到它关闭。这是正常的,还是我应该以某种方式尝试以其他方式启动该程序,使其仅显示为活动进程?如果我关闭启动程序的终端,程序就会随之终止。
谢谢
luk*_*sos 11
即使是旧的 bash 也使用 & 将进程发送到后台,但也没有其他方法..但基本的两个是这些:
1.)$~ your_command > outputfile_for_stdout &
# runs your command in background, giving you only PID so you can exit that process by `kill -9 PID_of_process`
# & goes at the end of row
2.)$~ your_command > outputfile_for_stdout
# this will run your program normally
# press Ctrl + Z then program will pause
$~ bg
# now your program is running in background
$~ fg
# now your program came back to foreground
3.)you can run terminal window under screen command so it will live until you either kill it or you reboot your machine
$~ screen
$~ run_all_your_commands
# Ctrl + A + D will then detach this screen
$~ screen -r will reattach it
Run Code Online (Sandbox Code Playgroud)
其他一些有用的命令:
$~ jobs
# will show you all processes running right now, but without PID
$~ ps
# will show you all processes for actual terminal window
Run Code Online (Sandbox Code Playgroud)