On Tue, 2019-10-22, Frederick Gotham wrote:
> I'm working on an embedded Linux project.
>
> When the computer boots up, a program called "Supervisor" is used to
> make sure that all background processes get immediately restarted if
> they crash.
>
> So let's say a process called "gas_monitor" gets run at startup. If
> it crashes 3 days later, then Supervisor will immediately restart
> it.
>
> Supervisor has limits though: If it tries to restart a process and
> it immediately crashes again, then it will try one more time to
> restart it, and then it will stop trying.
> When the computer is configured a particular way, for example let's
> say we change the config file from "gas_source=alkane" to
> "gas_source=halogen", then the "gas_monitor" program no longer has a
> purpose.
I'd prefer software documented as "if you change the config, you have
to restart" if at all possible. It's the traditional Unix way (well,
except daemons often reload their config on SIGHUP, but I bet many do that
by releasing resources and exec()ing themselves).
> Since "gas_monitor" is no longer needed, I can close it. . . but
> then Supervisor will try to restart it two more times, and it will
> close another two times. Then if the config file is changed back to
> "alkane", Supervisor won't try to restart the gas_monitor process
> because it's already failed the maximum times of two.
>
> So when 'gas_monitor' isn't needed, I just need to put it to
> sleep.
It's the wrong design. If it's important to not run it, then this
Supervisor thing needs to know (based on config) what processes to
supervise, and stop/never start the ones that are not needed.
Things get complicated once you have a Supervisor supervising things
which /pretend/ to work, when everyone knows they are really asleep on
the job.
> I want to do this the most efficient way possible (as I'm
> running embedded Linux and so CPU cycles are to be conserved).
What are you going to use those cycles for instead? Shouldn't you be
waiting for new config? Surely waiting on I/O doesn't use up CPU
cycles.
(Nothing C++-specific about the things above, by the way.)
> Using C++11, I think the best way to do this is:
>
> std::mutex m;
> m.lock();
> m.lock();
>
> Am I right?
I'd prefer pause(3) or similar, if you really never want to wake up.
It's not C++, but it seems unwise to avoid Unix APIs in a project like
this.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/
snipabacken.se> O o .