使用 init.d 将C++程序作为服务运行
Running a C++ program as a service using init.d
我用C++编写了一个程序,该程序在Raspberry Pi上运行,并在内置串行端口(循环中)侦听来自我设置的传感器网络的信息。我希望这个软件在 pi 启动时运行,所以我为此目的编写了一个初始化脚本。脚本成功启动该过程,因为数据被记录到我的数据库中,但是每当我使用"服务传感器记录器启动"时,我都会得到这个:
[....] 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 选项
开始-停止-守护进程 --开始 --安静 -b --oknodo --pidfile $PIDFILE --exec $DAEMON ;
相关文章:
- Active Directory:从网络服务帐户下运行的Windows服务调用ADsOpenObject时失败
- 从运行服务的应用程序代码中提取窗口句柄
- 在 Linux 上C++:在作为 systemd 服务运行时侦听键盘输入
- 将 Visual C++ 6 控制台应用程序作为 Windows 服务运行
- 使用C++在同一系统上运行的 2 个服务之间进行通信
- 当程序作为服务运行时重定向 std::cout
- 在 Windows 7 中从 Windows 服务运行 DLL/EXE 程序
- 我可以将一个可执行文件与另一个可执行文件(Windows 服务程序)组合在一起,并将该程序作为逻辑服务运行吗?
- 作为服务运行时连接到远程计算机的 WMI
- OpenSSL 在作为 win32 服务运行时SSL_CTX_new崩溃
- 获取当前登录的用户名,C++作为服务运行时不显示任何内容
- 使用 init.d 将C++程序作为服务运行
- 作为windows服务运行时,如何获取活动监视器的数量?C++
- 如何从作为服务运行的c++程序访问当前登录的用户信息
- 当java作为服务运行时,从java启动进程
- 保持ATL服务运行的最佳方法是什么?
- 在自动化服务部署时设置用户服务运行的最佳实践是什么?
- 从服务运行程序
- 在c++中将可执行文件作为服务运行
- 如何将dll作为服务运行