如何将程序作为服务运行(无声)?

我有一个基于python的服务器,我从终端开始。 然后终端的这个特定实例控制程序,程序将其用作一种记录窗口,直到它关闭。 这是正常的,还是我应该以某种方式尝试以其他方式启动程序,它只是显示为活动进程? 如果我关闭我启动程序的终端,程序就会死掉。

谢谢

即使是旧的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 

其他一些有用的命令:

  $~ jobs # will show you all processes running right now, but without PID $~ ps # will show you all processes for actual terminal window 

把它变成一个守护进程(服务)
daemon --name="yourservicename" --output=log.txt sh yourscript.sh

 $ servicename & 

使用&使程序在后台运行,而不是阻止shell直到程序结束。

您还可以使用:

 start-stop-daemon -SbCv -x your_command 

这是init.d脚本,用于在后台启动和停止程序 。

从终端你也可以运行screen或用&跟进你的命令。 轻松运行连续流程的方法。