Linux automatically restarts application upon failure - Daemons

I have a system with integrated linux, and it is very important that it runs continuously. Basically, this is the process of transmitting data from sensors and transferring this data to a database and web client.

If a crash occurs, how can I restart the application automatically?

In addition, there are several threads that perform polling (for example, sockets and uart communications). How to ensure that none of the threads hangs or comes unexpectedly? Is there an easy-to-use thread-friendly watchdog?

+5
source share
4 answers

Its essence is as follows:

  • , .
  • () , .

# 1, , , :

  • UNIX . , . , , .

  • . , , , .

# 2 PID fork + exec . , "" , "cron" - .

, - . - , , , , 100% . , tsan .

+6

, fork waitpid, . , .

. , , syscall alarm , ( sigaction ). alarm (.. , ), . , .
, , POSIX.

+6

You can create a CRON job to check if a process is started with start-stop-daemon from time to time.

+1
source

use script to run your application

#!/bin/bash

while ! /path/to/program   #This will wait for the program to exit successfully.
do
echo "restarting"                  # Else it will restart.
done

you can also put this script on your own /etc/init.d/in another to run as a daemon

0
source

All Articles