7 ms·
Beej's Guide to Interprocess Communication
- TrustPatches 3y agoAlmost done with Beej's Guide to Networking Concepts[1] and absolutely loving it, following along in Go. Gotta check this out and his other guides afterwards [1]: https://beej.us/guide/bgnet0/html/split/index.html https://beej.us/guide/bgnet0/html/split/index.html
- nunez 3y agoI was literally using Beej's networking primer today to build a simple TCP server in C. I haven't written C in a long time, so imagine my surprise when their code compiled and worked on the first try! In Docker! I had to add an extra sigaction to handle SIGINTs but nothing huge. Thank you so much for this guide. If you can't get enough Linux systems fundamentals, give Robert Love's Intro to Linux Systems Programming a try. It goes through IPC (but not in this much detail) and a good swath of Linux fundamentals, all in C.
- znpy 3y ago> I haven't written C in a long time, so imagine my surprise when their code compiled and worked on the first try! In Docker! C language is probably one of the most apt languages to write "timeless" software, and the Sockets api have been fairly stable over the years (although i know that the Beej's guide use some newer apis, mostly getaddrinfo). I was incredibly surprised when going through the source code of gnu make to find some incredibly old C syntax that happily compiled and is used today by pretty much everyone (one way or another). > If you can't get enough Linux systems fundamentals, give Robert Love's Intro to Linux Systems Programming a try. Interesting, I will! Thanks!
- bottled_poe 3y agoYou can probably thank Linus for that.. https://linuxreviews.org/WE_DO_NOT_BREAK_USERSPACE https://linuxreviews.org/WE_DO_NOT_BREAK_USERSPACE
- nunez 3y agoLinus is human sandpaper, but I fucking love this.
- charcircuit 3y agoFor people targeting Linux this guide is missing information about Binder and D-Bus which should be what you reach for by default for IPC.
- zlg_codes 3y agoWhat benefits will I gain as a programmer by targeting D-Bus instead of something less complex and generally more portable? D-Bus is how XDG and Red Hat software gets onto a Linux system. Without dbus, lots of software with braindead design can stay off of your machine. PIDs, sockets, FIFOs, and other similar constructs can achieve IPC just fine.
- fulafel 3y agoDepends a lot on what you are using IPC for. It seems to me parallelizing computation for performance, isolation/sandboxing, local usage/testing of netowork-able communication, and desktop/system services signaling are the most frequent use cases. Binder and dbus both target and work well for the desktop/system services part, and badly or not at all for the other 3.
- syntheticnature 3y agoMuch like the other Beej guides, the target isn't that tightly constrained. This aims at POSIX options, and attempts to cover gotchas for cross-platform code. Not to mention that just because you're only developing for Linux doesn't guarantee you'll have Binder or D-Bus.
- charcircuit 3y ago>the target isn't that tightly constrained Yes, which is why I highlighted that it is incomplete if you are not limiting yourself to just POSIX. It's important for readers to understand the scope of what is contained in the guide as it would be easy to think this is all the IPC mechanisms Linux offers. >developing for Linux doesn't guarantee you'll have Binder or D-Bus This is technically true, but everywhere Linux is used will likely already have one of them: embedded, mobile, desktop, server, etc. For D-Bus you can even have it work in a peer to peer mode where you don't need the daemon.
- dang 3y agoRelated: Beej's System V IPC Guide - https://news.ycombinator.com/item?id=36046014 https://news.ycombinator.com/item?id=36046014 - May 2023 (1 comment) Beej's Guide to Unix IPC (2015) - https://news.ycombinator.com/item?id=29829483 https://news.ycombinator.com/item?id=29829483 - Jan 2022 (54 comments) Beej's Guide to Unix IPC (2010) - https://news.ycombinator.com/item?id=9619375 https://news.ycombinator.com/item?id=9619375 - May 2015 (31 comments) Beejs Guide to Unix IPC - https://news.ycombinator.com/item?id=1525227 https://news.ycombinator.com/item?id=1525227 - July 2010 (19 comments) Beej's Guide to Unix Interprocess Communication - https://news.ycombinator.com/item?id=978558 https://news.ycombinator.com/item?id=978558 - Dec 2009 (20 comments)
- perihelions 3y agoThere are several more with abbreviated titles, https://news.ycombinator.com/item?id=29829483 https://news.ycombinator.com/item?id=29829483 ("Beej's Guide to Unix IPC")—Jan. 2022 (54 comments) https://hn.algolia.com/?query=beej.us/guide/bgipc https://hn.algolia.com/?query=beej.us/guide/bgipc
- dang 3y agoAh thanks! I've augmented the list in my comment.
- suprjami 3y agoCould this text be automated for each submission and included at the bottom of the comments? Not as a post by you but as a site feature.
- dang 3y agoIt's harder to automate this than it looks, because (1) you can't just test for identical URLs, and (2) we want to distinguish interesting from uninteresting threads (so that we can just list the interesting ones). It's definitely on the list to figure out how to build as a site feature though—perhaps a sort of community curation thing.
- locusofself 3y agoWow, I remember following Beej's socket tutorial somewhere around the year 2000 . perhaps even before that.
- synergy20 3y agolast time I read it,it was all sysv ipc,but I think we should do posix ipc instead these days?
- stevefolta 3y agoI've been using pipe() lately (along with poll()) to tell threads to quit, and other simple inter-thread signalling. Super easy, very little code needed. I guess socketpair() would work just as well.
- jcelerier 3y agoAfter writing the same kind of code involving pipes semaphores or whatnot dozen of times, I really enjoy c++20's std::jthread taking care of the cancellation entirely automatically
- andreareina 3y agoWhat's the conventional location for unix domain sockets if XDG_RUNTIME_DIR is unset? /tmp?
- teddyh 3y agoThat’s where the X11 server puts its socket, but I think the modern convention is /run, though.
- mytailorisrich 3y agoIt would also be useful to mention the POSIX API for shared memory, which is based on memory-mapped files neatly located under /dev/shm.
- throwaw12 3y agoBrian (beej71), if you are here, how do you write such concise guides? I remember long ago I started learning network from your guide because TCP/IP illustrated felt like too big to start with.
- Timpy 3y agoWhen I took my graduate level operating systems class we had to do a bunch of coursework in C. Beej's Guides are the reason I passed that class. Thank's Beej!
- marksimi 3y agoCame here to say the same. 100% not passing that class without Bern’s Guides.
- halayli 3y agoYounger crowd might not understand but back in late 90s early 2000 it was rare to find quality content/tutorials that are beginner friendly. Beej's Guide was one of the best quality content back then and even after 20 years it still stand in the first place in the topics covered.
- sebstefan 3y agoI got my degree in 2020 and still used Beej's guide for the Socket API There was nothing like it elsewhere
- tentacleuno 3y agoIsn't it still a bit rare? I mean, to get any valuable results, I have to run uBlacklist (a search engine results filter) with a fairly large set of filters. Having a well-written tutorial on one page, with no monthly fees, licensing, SEO, or ads (and someone who actively responds to emails!)... that's still quite rare, at least in my experience.
- sitzkrieg 3y agoyea, thats why pointed out as still the defacto best still to this day sadly
- brodouevencode 3y ago~~Repost from 47 days ago https://news.ycombinator.com/item?id=37842863~~ https://news.ycombinator.com/item?id=37842863~~
- tentacleuno 3y agoThis is the guide on IPC; you've linked the one on network programming.
- brodouevencode 3y agoYou are right. My bad.
- kieckerjan 3y agoTangential. A file lock is released if the locking process exits. This can be leveraged to make a poor man's semaphore that is automatically raised if the process exits. Slow but solid if you want to control the number of simultaneous crash prone processes that have access to a resource.
- samsquire 3y agoI find interprocess and program (or subprogram) or coroutine communication fascinating, as I've said before it seems a large part of the complexity of computing is the "logistics of data" or data movement. (See calling conventions, network protocols, data flow in pipelines as in Linux pipes or Kafka, interfaces, APIs, REST APIs and socket servers as other Beej tutorials) An API is just arranging something into a known position in memory or registers before jumping in control flow and where to go when it is finished. I have spent a lot of time recently doing hobbyist programming with multithreaded ringbuffers and barriers for concurrency and I'm still looking for a golden abstraction that is easy to reason about - and doesn't suffer from low level mutexes and worrying about memory ownership when transferring data between threads or processes. I really like the ideas behind Smalltalk about communicating objects and the composition of "behaviours" through communication of objects. I have never used Dbus but I think that's kind of similar. And I think The COM object model and Mozilla's XPCOM model are similar ideas that were tried which is about a standard protocol for object communication and initialisation. It reminds me of the perennial userspace vs kernel debate, microkernels vs monolithic kernels. How do you efficiently communicate between programs? And how do you efficiently communicate between parts of the same program without coupling them? Every programming language defines its own semantics. You kind of need to serialize and deserialize data sent between programs for safety. A procedure call (CALL instruction) is efficient communication with registers and the stack and it controls flow directly and isn't parallel. A coroutine is efficient communication at runtime between two or more regions of code. What do you think? Would love to hear what other people are doing in this space and how you've used interprocess communication or even Dbus.
- pyinstallwoes 3y agoComputing is really transformation of energy/information. :) Programming are the mental models and languages to facilitate that action.
- samsquire 3y agoI see your profile about energy. Where do you see God in all this :-)