Suppose there is a program in C. We launch it, and if it crashes, then you need to immediately launch it again. Tell me how to do it

  • 2
    Depends on the program and what you call crash. - avp pm
  • 3
    The right way is to cut all unsafe logic into a separate process, fork'атьcя or spawn'ить new process / processes and do work in them. The main process at the same time can poll'ить these separate processes (well, or do something a little more clever) and restart them in case of crashes. - Costantino Rupert

3 answers 3

We are using the option via inittab. Application example (for system V):

 process:3:respawn:/opt/bin/our_respawining_process 

For system.d is slightly different. Create a config in / etc / init / Let me give you an example to run uwsgi

 # file: /etc/init/uwsgi_project-prod.conf description "uWSGI server for project-production" start on runlevel [2345] stop on runlevel [!2345] respawn # This is where you stipulate which set of settings in your ini file you will use. # You could specify "production" at the end of this command instead of "development" to use a different configuration setup in your ini file. exec /usr/bin/uwsgi --ini /etc/uwsgi.ini:production 

    Monit, for example, hangs by a daemon and checks once a minute if there is such a process, if not, starts it again.

      Well, as an option - in the error handlers in the code, use the exec system call.