linux - start-stop-daemon 启动多个进程

标签 linux bash

我正在尝试使用 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/

相关文章:

linux - 系统上不存在 JDK,但系统表示需要将其删除

bash - 添加单个 Bash 命令

c++ - X11 - 清空屏幕

linux - 如何限制 Linux 中程序的网络带宽?

linux - 属性错误 : module 'tensorflow.python.summary.summary' has no attribute 'scalar'

linux - 将多个 PDF 文件合并/转换为一个 PDF

c - 从/proc/pid/stat中的tty_nr属性获取次设备号

mysql - 如何提取分隔符前后的字符串并存储在mysql中?

linux - greping后如何从文件中提取内容?

linux - 如何在 Linux 中获取分组文件的总数以及扩展名和路径