5 ms·
I did something similar some time ago, but in far simpler form. I called it "process race" - prace for short. Basically you write simple shell script to start
by hawski 11y ago
I did something similar some time ago, but in far simpler form. I called it "process race" - prace for short.
Basically you write simple shell script to start your processes and at the and you exec prace so it takes over children of shell:
#!/bin/sh
proc1 &
proc2 &
proc3 &
exec prace
You could also do this as a part of shell script in this way:
(proc1 & proc2 & proc3 & exec prace)
Then prace has simple job. It wait(2)s and then kills all children.
I have it somewhere if someone is interested, but I can access it in few hours. But everything is written in at most 2/3 terminal screens worth of C.
- gkya 11y agoI for one would like to have it at hand, if you could. Just paste it here if you don't mind publishing it, thanks in advance.
- hawski 11y agoFor the time being I can't access original implementation, but quick and dirty version looks like this: https://gist.github.com/hadrianw/8e6f9c1007953b37f768 https://gist.github.com/hadrianw/8e6f9c1007953b37f768
- hmpc 11y agoThis is the service supervision approach, which is indeed the best, avoiding race conditions and nasty polling. If you really must monitor processes which you cannot parent, at least under Linux you can do this using ptrace to sort-of-reparent the processes (as long as you have CAP_SYS_PTRACE or your ptrace scope is set to 0 in Yama), with waitpid to monitor all of them.
- deleted 11y ago[deleted]