我正在尝试使用 start-stop-daemon 来启动一个在后台运行的进程。据我所知,如果第二个进程已经在运行,start-stop-daemon 应该可以防止第二个进程启动。我现在运行的脚本相当简单:
#!/bin/sh
while true; do
date > /home/pi/test/test.txt
sleep 10
done
我正在使用 start-stop-daemon --start -v -b -m --pidfile/var/run/test.pid --exec/home/pi/test/test.sh 启动脚本
我能够使用 start-stop-daemon --stop -v --pidfile/var/run/test.pid
成功停止脚本
但是,如果我运行启动命令两次,它将启动两个进程,而不是我期望的一个。启动命令是否在启动进程之前检查 pid 文件,或者是否需要执行其他操作才能发生?
最佳答案
man page of start-stop-daemon包含关于在脚本中使用 --exec 选项的特殊警告。
-x, --exec executable
Check for processes that are instances of this executable. The executable argument should be an absolute pathname. Note: this might not work as intended with interpreted scripts, as the executable will point to the interpreter.
当您运行脚本时,实际启动的进程是脚本的 shebang 行中注明的解释器。这会混淆 start-stop-daemon 实用程序。
顺便说一句,您可以使用 -t 选项来调试 start-stop-daemon 的此类问题。
关于linux - start-stop-daemon 启动多个进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37885003/