簡體   English   中英

使用init.d將C ++程序作為服務運行

[英]Running a C++ program as a service using init.d

我已經用C ++編寫了一個程序,該程序在Raspberry Pi上運行,並在內置串行端口(循環)上偵聽來自已建立的傳感器網絡的信息。 我希望該軟件在pi啟動時能夠運行,因此我為此編寫了一個初始化腳本。 該腳本成功啟動了該過程,因為數據已記錄到數據庫中,但是每當我使用“ service sensorlogger start”時,都會得到以下信息:

[....] Starting the process: sensorlogger

它只是坐在我的命令行上,直到我結束程序。

  • 為什么即使進程正在運行,我也無法恢復終端,我可能會尋求什么解決辦法?
  • 這會在pi啟動時阻止我的進程啟動還是阻止它啟動其他服務?

我的摘錄如下。 如果需要,我可以包括整個腳本。 在此先感謝您提供的任何幫助!

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-stop-daemon --start --quiet -b --oknodo --pidfile $ PIDFILE --exec $ DAEMON;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM