You are not logged in.
Pages: 1
I've got a binary that executes once xorg is started. Periodically it will die off. Is there a simple method that would check to be sure that this is still running and if not, start it again?
Offline
You can run it in a loop.
What is the program? Does it give a particular (or any non-zero) exit code when it quits unexpectedly?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
while :; sleep 5; if ! ps -C yourProcess; then (yourProcess &); fi; done
Offline
HiImTye, that's a bit more complex than needed:
while :; yourProcess; done &
would do. Both of these, however, make actually quitting intentionally non-trivial. This is why I asked about the exit code. The following would be best if it will work:
while [[ $(yourProcess) -ne 0 ]]; do :; done
EDIT: I guess this depends on if the process puts anything on stdout too ...
Last edited by Trilby (2014-05-14 20:09:13)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
while :; do yourProcess; done &
I had no idea until now this syntax would work lol
Last edited by HiImTye (2014-05-14 20:11:09)
Offline
You could run it as a systemd service with 'Restart=' set to an appropriate value (see man systemd.service). This would always restart it or perhaps only when it failed, depending on the values you set.
Scott
Offline
HiImTye, that's a bit more complex than needed:
while :; yourProcess; done &
would do. Both of these, however, make actually quitting intentionally non-trivial. This is why I asked about the exit code. The following would be best if it will work:
while [[ $(yourProcess) -ne 0 ]]; do :; done
EDIT: I guess this depends on if the process puts anything on stdout too ...
Of course, if you test the output, it depends on the output. If you test the exit code, it depends on the exit code:
while ! yourProcess; do :; done
Offline
Offline
If you wrote it by yourself, just fork it. If the child dies, the next fork will jump in...and so on.
Offline
It's unfortunately not mine. One thing....I would like it to execute after I start X.
Offline
So ... put it in your xinitrc.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Ah ok. I had it in the jwmrc and it would die and not restart.
Offline
Pages: 1