8 ms·
Show HN: Pact, a simple utility that kills all procs given to it if one dies
- tomc1985 11y agoPact... heh heh... I like the name :)
- Vintila 11y agoSometimes I wonder if people come up with the name first and write something to match.
- MonadQueen 11y agoThis is like the Erlang / OTP "One for All" strategy. http://www.erlang.org/doc/design_principles/sup_princ.html http://www.erlang.org/doc/design_principles/sup_princ.html
- rdtsc 11y agoI was actually thinking of process linking. Any groups of processes can be linked. Processes that are linked together -- die together.
- otoburb 11y agoThe combination of the ghoulish name and correspondingly succinct description brings to mind the style of a Magic: The Gathering card.
- bobbles 11y agoAnd such a card exists! http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=247142 http://gatherer.wizards.com/Pages/Card/Details.aspx?multiver...
- loarabia 11y agoBecause of this post and these comments I'm now wondering if M:tG is Turing complete. <heads off to google>
- PeCaN 11y agoSpoiler: yes. I wonder if there's anything in the rules to deal with the fact that a game might never complete.
- raker 11y agoIf there is a truly unstoppable loop (considering usage of the word "may" or such optional ability to continue or break a loop) then the game is considered a tie. There are tournament rules regarding players intentionally drawing out the game (it's against the rules), but I don't think there's any rule against a deck that simply runs long (or really long).
- thaumasiotes 11y agoSome cards have been banned for causing tournament rounds to run too long, or for being central in decks that regularly do this (I believe Sensei's Divining Top and the "eggs" deck were the major offenders).
- tikhonj 11y agoTournaments run with a time limit. After the time limit, the game ends in a set number of turns. There are also rules for "slow play" that generally keep a single turn from lasting too long—and inadvertently prevent certain weird combinations of cards from working. Online play has what is effectively a chess clock. This doesn't work in person because the game involves "priority" passing between players after every single action, which would be difficult to do manually. Additionally, play in person relies on a whole bunch of "shortcuts" that skip steps if both players don't want to do anything, which would make timekeeping even more difficult. But if you left out these tournament-specific rules and just played the game rules, you could have games going on arbitrarily long. Since you can create "tokens" you can have arbitrary amounts of state, so a game could even loop without ever hitting the same game state twice. (Think "puffer trains" from the John Conway's Game of Life.)
- gohrt 11y agoThat's a disgustingly insensitive name.
- voltagex_ 11y agoI'm sorry, but I disagree with this current trend of making language "safe" for everyone. Yes, I know about triggers and some good reasons for changing words (there's no real reason to be using master/slave in a new piece of software). Eventually you end up with bland, uninteresting language. Pact, while a little confronting if you follow the connotations far enough, is an excellent and succinct name. I would have also accepted "contract".
- nness 11y agoI disagree. It is very succinct though.
- zensavona 11y ago... why? A pact, from Latin pactum ("something agreed upon"), is a formal agreement.
- otoburb 11y agoThe OP is not upset about the name alone, but against the twinge of realization that dawns after reading the accompanying description.
- logical42 11y agoI'm not exactly sure it's possible to describe killing processes much differently.. I mean the Linux command to kill a process is 'kill'..
- DrScump 11y agothe kill command just sends the signal of the user's choice, not necessarily SIGTERM (the default) or SIGKILL or whatever. This lets you change behavior in a running process from the shell by triggering a desired handled signal.
- gnufied 11y agoProps for this. Just last week, I was searching for a similar solution and ended up coding this - https://github.com/code-mancers/invoker/blob/master/lib/invoker/power/setup/files/invoker_forwarder.sh.erb https://github.com/code-mancers/invoker/blob/master/lib/invo... It doesn't kill the shell, when one of the process dies but kills the processes if shell dies. There is some trick involved in the way trap gets called though when shell dies and without waiting on the processes twice - shell exits without killing child processes.
- Terr_ 11y agoI wonder if you could create a system that gives a file-lock to the last surviving (child?) process... Call it Tontine.
- sandGorgon 11y agoThis is great, and if you can - you should probably submit it as a request to systemd and supervisor. I can see how I would use it in supervisord within a group.
- deleted 11y ago[deleted]
- blantonl 11y agoI don't get it.. The name that is.
- RunawayGalaxy 11y agoI assume it's Pact as in "death pact".
- azianmike 11y agoI might be totally wrong, but isn't this a good way to get orphaned processes? Kill the parent arbitrarily with SIGTERM (I don't think this automatically cleans up the children/forked processes) and viola, you've got an orphaned process.
- sebcat 11y agoUsing this would require whatever process you start to handle SIGTERM properly. Most processes spawning children do this, but it's no guarantee and one needs to be aware of this. In my experience, processes doing IPC with parent gets notified of parental death by EOF on the socketpair/pipe it's using to communicate with the parent. This is easy to reason about and most people check return values from I/O functions. Parents spawning children and only caring about SIGCHLD are more prone to not have the correct signal handlers set up by its dev(s). IMO, any process spawning children w/o proper signal handlers are not good citizens.
- kazinator 11y agoI'd call this "atomic bomb". If allusions to suicide pacts are fair game, so is mass killing; and atomic means "all or nothing" in CS.
- dbpokorny 11y agomore like a "fuse" that cuts off power to X and Y when Z fails
- zappo2938 11y agoOver at MongoDB, Inc. atomic means nothing at all.
- jeswin 11y agoMongoDB is quite decent these days. Their WiredTiger backbend is written by the Berkeley DB guys.
- gkya 11y agoWe can also call it hitler as it does a 'process genocide'. Or maybe we can use a proper name like 'killtogether' or 'killpg' for kill process group. The name should correlate to the function of the thing.
- nodesocket 11y agoDoes it make sense to optionally pass the signal you want to send as an argument? pact --signal SIGINT $PID1 $PID2 pact -s SIGKILL $PID1 $PID2 pact $PID1 $PID2 # uses SIGTERM by default
- nickodell 11y agoI wrote this to scratch an itch. Is this a feature that would make pact useful to you? If so, I can add it. I debated about making it send SIGKILL shortly after sending SIGTERM, but I was having troubling thinking of an unsurprising way to implement it.
- nodesocket 11y agoI can't think of a current itch, but think about sending SIGHUP (refresh config) instead of killing processes.
- ufo 11y agoI wonder what happens if you give it its own process ID.
- JoachimSchipper 11y agoThis is a neat hack, but pids are reused - there is a reason "proper" supervisors take care to be the parent of the supervised process. (A process monitoring system will mostly trigger under odd conditions... such as fork bombs.)
- nickodell 11y agoYou're right, but I think it's an acceptable risk. pact wakes up every second to check that every process is still there. If the process is gone, it sets the procChanged field in the struct, and it won't kill it later.
- int0x80 11y agoStill, what you are doing is inherently racy. The very moment you pass the PIDs to your program, they can already be gone and reused. You can end up kill()ing a different PID. I don't think you can use this for anything serious. In what situation do you think it might be acceptable? EDIT: You are trying to implement process groups in user space.
- hawski 11y agoI 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]
- rusanu 11y agoIf you happen to target Windows platform (I know article does not), don't reinvent the wheel. There are NT Job Objects [1] for this. The 'target' process creates the job with `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE` set and keeps the job handle open. 'dependend' processes (by default all children spawned by 'target', but you can add more) will all be killed when the 'target' process terminates, no matter how is terminated. Jobs can do more, like cap CPU/IO/Memory for the job. [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms684161(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms6...
- quakenul 11y agoI fucking love the name =)
- x1024 11y agoI'm just sitting here - popcorn-in-the-microwave - waiting for those people to start a fuss about it.
- polm23 11y agoMaybe this is a silly question, but what's a situation where you would want to use this?