gpt4 book ai didi

c++ - 使用 init.d 将 C++ 程序作为服务运行

转载 作者:太空宇宙 更新时间:2023-11-04 11:01:20 29 4
gpt4 key购买 nike

我用 C++ 编写了一个程序,该程序在 Raspberry Pi 上运行,并在内置串行端口(循环)上监听来 self 设置的传感器网络的信息。我想让这个软件在 pi 启动时运行,所以我为此编写了一个初始化脚本。该脚本成功启动了该过程,因为数据已记录到我的数据库中,但是每当我使用“service sensorlogger start”时,我都会得到:

[....] Starting the process: sensorlogger

它只是位于我的命令行上,直到我 ^C 结束程序。

  • 为什么即使该进程正在运行,我也没有取回我的终端,我应该如何解决它?
  • 这会阻止我的进程在 pi 启动时启动或阻止它启动其他服务吗?

下面是我的 initscript 的摘录。如果需要,我可以包含整个脚本。在此先感谢我能得到的任何帮助!

test -x $DAEMON || exit 5
case $1 in
start)
# Checked the PID file exists and check the actual status of process
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
# If the status is SUCCESS then don't need to start again.
if [ $status = "0" ]; then
exit # Exit
fi
fi
# Start the daemon.
log_daemon_msg "Starting the process" "$NAME"
# Start the daemon with the help of start-stop-daemon
# Log the message appropriately
if start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON ; then
log_end_msg 0
else
log_end_msg 1
fi
;;

最佳答案

尝试添加 -b 选项

启动停止守护进程 --start --quiet -b --oknodo --pidfile $PIDFILE --exec $DAEMON ;

关于c++ - 使用 init.d 将 C++ 程序作为服务运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26950365/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com