15 ms·
Show HN: A “living” Linux process with no memory
- ebg13 7y agoIt's 2020. You couldn't have done this in Python3?
- meddlepal 7y agoThere's nothing wrong with using Python 2 for a PoC.
- Wowfunhappy 7y agoI'd be much more reluctant to get on OP’s case about it than GP, but there’s a strong argument to be made that this hurts the overall python ecosystem.
- kick 7y agoThere's also a strong argument to be made that people shouldn't have to care about ecosystems that are so delicate that a proof of concept in a previous version "hurts the overall [ecosystem]." "How dare you use a hammer! We're all using Hammer 2 now! I don't care that it was 'Only one nail," put it down and pick up Hammer 2! Your hammer is what, ten years old? That's ancient! It's not even compatible with my Hammer 2! What do you mean, 'They hit the same fucking nails!' That's not the point! I can't track how many nails you're hitting per-minute now, or even take advantage of the nails you've hit! It's barbaric!" Can you imagine?
- deleted 7y ago[deleted]
- Dylan16807 7y agoTo make the analogy work I have to imagine that the two hammers cause horrible problems when used at the same time, and that they're both free with 5 minute shipping. It's a sucky situation to be in, but we should probably get everyone on the same hammer. (If we want a somewhat less nonsensical analogy, replace hammer with screwdriver. Two incompatible screw head patterns and you can only use one driver on any particular object.) So sure don't nitpick a toy project, but if someone's writing significant code in python 2... it's not ideal. - But all of this is a dumb tangent, and we should just appreciate how funny it is to ask that this nonsensical pointless quasi-OS-breaking code be done in python 3 instead.
- kick 7y agoNo "horrible problems" arise from Python 2 being used on the same system that Python 3 is on. The only problems are trivial, which was highlighted in the analogy.
- Dylan16807 7y agoI didn't say same system, I said same time. As in, trying to run one program with both.
- kick 7y agoWouldn't occur in this case, as the script starts with: #!/usr/bin/env python2
- Dylan16807 7y agoYou're arguing against something I never said. Yes, this file, completely in isolation, has no problem. But people want to different pieces of python code together. If one or the other only works with a specific version, it becomes a problem when you try to combine them. Therefore, best practice is to get everyone on the same version. We want to stop having to ask which version everything is, and facing the disappointment when things can't go in the same program. We want to get back to the situation where it's just 'hammer', and that's good enough for 95% of people.
- kick 7y ago...use the hammer that didn't arbitrarily break compatibility, then? (Note that the original analogy pointed out that they couldn't be mixed, anyway: "or even take advantage of the nails you've hit!") This is like complaining that the well is poisoned when you're the one who put arsenic in it. This also isn't even an open source project, so it's not like you can mix and match anyway.
- 7y ago
- rat9988 7y agoHe could. You also could have done it in Python3, and you still can.
- klyrs 7y ago"He" is named Isabella. https://github.com/izabera https://github.com/izabera
- darkwater 7y agoWhy pointing this detail out is being downvoted? It is a polite message and it is correct above all. Don't upvote it if you think it's not that relevant (I personally think it is) but don't downvote it either.
- OJFord 7y agoMaybe it's a level deeper, the down-voters objecting to the assumption that 'he' can't be called 'Isabella'! (I haven't voted either way and have no strong feelings on it, just pointing out how doomed this line of objection/correction is. Personally I generally say 'they' or 'the OP', and did long before (all my life) I was aware of anyone having pronoun preferences, it's just correct isn't it? Never used to be a problem. 'Is that a person over there?' 'Yes, they're just in a funny pose.')
- deleted 7y ago[deleted]
- Cerium 7y agoI thought you were joking, I assumed it would be C. Thanks for getting me to take a look at the code.
- saagarjha 7y ago(For the lazy: it is in C, but to reliably make a system call that will uninterruptibly block there's a Python FUSE driver that hangs to cause the call from C to block.)
- thrwwy314159265 7y agoYou are seriously getting bent out of shape over just 5 freaking lines of code?
- anonu 7y agoCan't think of any way to profit from this. Just reboot your box.
- taftster 7y agoThat's the '???' part of it, I would assume.
- hsnewman 7y agoCan this be implemented in Go?
- stevemk14ebr 7y agowe're programmers, anything can be done with enough time or money
- state_less 7y agoCan you write a program to tell if any given program is going to halt?
- deleted 7y ago[deleted]
- cwp 7y agoTell you what: you give me time and money, and I'll work on this program. Keep giving me time and money until I tell you I've succeeded.
- saagarjha 7y agoCan someone write a program to tell me how much money I’d need to give you?
- kd22 7y agoGive me time and I'll tell you at the end how much money you need to give me.
- state_less 7y agoNo need to be difficult, just give me an estimate. Is this going to be a small, medium or large t-shirt size task?
- 7y ago
- croo 7y ago> Why? I don't know. I thought it was funny This is the profit. While job searching I went on an interview where I got asked why I did a side gig listed on my resumee. "For friend or for money?" It was neither and I said "I don't know, because programming is fun?" I got hired.
- Waterluvian 7y agoPeople who do stuff like this remind me of the Beethoven quote: "Don't only practice your art, but force your way into its secrets; art deserves that, for it and knowledge can raise man to the Divine." Why are you learning how to create linux processes with no memory? Why are you hacking overloading into Python? Why are you writing programs for fun? To dig unnecessarily deep and force your way into programming's secrets.
- gpanders 7y agoWell said, and good quote.
- jldugger 7y ago> I got hired. So, for money.
- jshevek 7y agoNot all of the outcomes of our actions give evidence for the motivations for our actions.
- osrec 7y agoEspecially given how rarely our desired outcomes match our original motivations... We try to achieve one thing, but often end up achieving something else!
- Piskvorrr 7y agoI've had projects that - eventually and incidentally - brought me money, but were not started or done for money.
- geofft 7y agoI've now seen a similar case multiple times in the wild - if a process has a thread in uninterruptible sleep (e.g., blocked on a bad disk or a stuck network filesystem) and you kill it, the process dies, but the kernel waits forever for that thread before informing the parent process. The parent doesn't get SIGCHLD, and wait() doesn't return. (So, for example, your favorite init/supervisor won't restart the process or even realize the process has died and raise an alert.) If the thread wasn't the first thread, then the process looks like it's gone and stops having most information in /proc/$pid, but it's still got the thread in /proc/$pid/tasks/. I've taken to calling such a process a "lich," because it's not quite a zombie - the parent can reap a zombie by calling wait(), but the lich has used magic to avoid true death.
- btown 7y agoCan/do supervisors poll for this situation? Seems like that should be possible.
- xenadu02 7y agoAlso curious why the kernel can't abandon the thread since the process is dead anyway; set a bit in kernel space so on the walk back from the syscall it bails out instead of trying to return to userspace. That doesn't solve the kernel thread being stuck forever problem. I'm not sure what the fix is there... is it bad drivers with no timeout mechanism? I don't know how they'd do that unless the kernel IO is all async anyway. Just tearing down the kernel thread seems likely to leave the locks abandoned in bad states.
- cryptonector 7y agoThe kernel can't abandon that thread entirely, but it could "detach" it from the process it was part of and arrange for it to clean itself up and disappear if ever it wakes. And so the parent process could get told of the child's death.
- jerf 7y agoThis becomes a tarpit. Whatever metric you think to measure for this may itself become a source of false positives in the field. Whatever things you choose to try to avoid that becomes another source of falseness in the system. This tends to cascade as people apply patch upon patch until you have a system that basically randomly fails and nobody can tell you why. This is not a theoretical report; in theory this approach can work, if you get it perfect enough. This is a practical report, both of systems I've built myself and of many other such cases I've witnessed, including some things around process management and supervision. In the end, you really have little choice but to trust what the OS is telling you, and if the OS is lying for whatever reason, to fix the OS. As hard as that last bit may be as a solution, it still turns out to be the easiest, most-effective fix. And it may not be a perfect fix, either... but it'll still be the best.
- Arch-TK 7y agoReally neat! Not sure why people care what it's written in. I'm pretty sure people wouldn't complain if this was a blog post written in english rather than a program written in C and python2.
- plumsempy 7y ago...and thus pure consciousness was born.
- AgentME 7y agoMy new meditation strategy is to visualize myself as a process with no memory waiting in uninterruptible sleep.
- kees99 7y agoDid anybody try to run it? Python part of this PoC depends on python2 module "fuse", which in turn depends on "gunpowder", "a library to facilitate machine learning on large, multi-dimensional images". What is even going on here? $ pip2 install fuse Collecting fuse Downloading https://files.pythonhosted.org/packages/c3/f6/82777531d0dd0fa1d1b509258873f4b48e1ec702dcf0258214fafb474895/fuse-0.1.3.tar.gz ERROR: Packages installed from PyPI cannot depend on packages which are not also hosted on PyPI. fuse depends on gunpowder@ git+https://github.com/funkey/gunpowder@721718b6569b47a2f5d5d6633c76c85f779e25c7
- notpeter 7y agoPretty sure they meant to depend on python-fuse not fuse. The former is python bindings to libfuse. https://github.com/libfuse/python-fuse https://github.com/libfuse/python-fuse
- michens 7y agoI think it's meant to depend on the fuse-python (https://pypi.org/project/fuse-python/ https://pypi.org/project/fuse-python/). fuse is something else
- kristjansson 7y agoI think you want https://pypi.org/project/fuse-python/ https://pypi.org/project/fuse-python/ instead. That python packages can and often do have different names than their corresponding distributables is ... not great.
- mikepurvis 7y agoI agree that it's terrible, though it can be nice in cases where a package ends up forked— for example allowing Pillow to be a drop-in replacement for PIL.
- deleted 7y ago[deleted]
- MiroF 7y ago
- kdom13 7y agoAs someone who doesn't understand much of what's going on here, what resources would you suggest I study to improve?
- gouggoug 7y agoIt kind off depends on what exactly you don't understand, but a book about Operating Systems and Linux Programming are probably what you want to read. They'll teach you about threads, segfault, the meaning of uninterruptible sleep, signals, the /proc/ directory, etc.
- kdom13 7y agoCan you suggest a book about Operating Systems?
- mgbmtl 7y ago"Operating System Concepts" by Silberschatz, Galvin and Gagne, is a classic. It covers the basics: processes, syscalls, filesystems. (it's what we read in our OS course in university)
- kdom13 7y agoThank you!
- foxrob92 7y agoI'd suggest "Operating Systems: Three Easy Pieces". (http://pages.cs.wisc.edu/~remzi/OSTEP/ http://pages.cs.wisc.edu/~remzi/OSTEP/) I've found it very accessible. Largely, the way that they teach is to describe a system based on a set of assumptions, then slowly relax each of the assumptions one by one until you reach an example of a real system. That style of teaching really works for me.
- kccqzy 7y agoA more pragmatic book is The Linux Programming Interface, by Michael Kerrisk. It is Linux-specific though, but that's probably fine. Uninterruptible process sleep is covered in section 22.3. Threads, in chapters 29–33. Signals, chapters 20–22. The proc file system in section 12.1. Memory mappings, chapters 49–50.
- seqizz 7y agoI am not sure if uninterruptable sleep is considered "living", but fun experiment.
- fierro 7y agohow does the FUSE filesystem interact with the c program running? I don't see the C program attempting to r/w to that x directory
- saagarjha 7y agohttps://github.com/izabera/zeromaps/blob/85ffcf82f7eb8365ebffea755f475d97d6d1d889/zeromaps.c#L9 https://github.com/izabera/zeromaps/blob/85ffcf82f7eb8365ebf...
- fierro 7y agowhy do we need to JIT the munmap code? Can we not just call munmap(2)
- spc476 7y agoThe call to munmap() requires both a stack (which will be unmapped at some point) and the code from libc (which will be unmapped at some time). The program gets a list of all the allocated pages first, then creates one more for the JIT code (and a copy of the list) which is unmapped as the last thing it does. There really is no other way of doing it.
- emmelaich 7y agoCan it be done without fuse? Fuse is restricted; probably for reasons like this.
- sargun 7y agoHa. It isn't. User namespaces allow you to do this attack: I have a reproduction here: https://github.com/sargun/fuse-example https://github.com/sargun/fuse-example Basically, what’s happening is that the FUSE daemon which is the one handling the FUSE requests has /dev/fuse open. There is a thread in that FUSE daemon. let’s call the FUSE daemon P10, and the thread P11. P10 wires up a FUSE filesystem on /tmp, it opens /dev/fuse with FD5 P11 enacts an uninterruptible (blocking operation) on /tmp/foo, called OP1, and /tmp/foo is FD6. P10 reads the operation (OP1) from /dev/fuse, so now OP1 is in userspace ----The Pid 1 of the namespace is killed-- P10 just terminated, and cannot make progress. It will never respond to OP1. FD5 and FD6 remain open, because P11 is in uninterruptible sleep. P11 is in an uninterruptible disk sleep waiting for OP1 to respond, and the fuse connection never aborts. FUSE abortion doesn’t kick in because the FD of `/dev/fuse` that P10 originally opened as the FUSE daemon under FD5 will not be closed until all threads as part of the process are terminated. The mount namespace wont be torn down until P11 is torn down. P11 will never be torn down because it’s waiting for someone to do something.
- peter_d_sherman 7y agohttps://lwn.net/Articles/288056/ https://lwn.net/Articles/288056/ Excerpt: "There are advantages and disadvantages to each type of sleep. Interruptible sleeps enable faster response to signals, but they make the programming harder. Kernel code which uses interruptible sleeps must always check to see whether it woke up as a result of a signal, and, if so, clean up whatever it was doing and return -EINTR back to user space. The user-space side, too, must realize that a system call was interrupted and respond accordingly; not all user-space programmers are known for their diligence in this regard. Making a sleep uninterruptible eliminates these problems, but at the cost of being, well, uninterruptible. If the expected wakeup event does not materialize, the process will wait forever and there is usually nothing that anybody can do about it short of rebooting the system. This is the source of the dreaded, unkillable process which is shown to be in the "D" state by ps. Given the highly obnoxious nature of unkillable processes, one would think that interruptible sleeps should be used whenever possible. The problem with that idea is that, in many cases, the introduction of interruptible sleeps is likely to lead to application bugs. As recently noted by Alan Cox: Unix tradition (and thus almost all applications) believe file store writes to be non signal interruptible. It would not be safe or practical to change that guarantee." That's the whyness to all of this...
- Reelin 7y agohttps://eklitzke.org/uninterruptible-sleep https://eklitzke.org/uninterruptible-sleep > If the process is in uninterruptible sleep then the process can’t be interrupted, which will cause the strace process itself to hang forever. Remarkably, it appears that the ptrace(2) system call is itself uninterruptible, which means that if this happens you may not be able to kill the strace process! Everything about this is broken and makes no sense. The Night Watch is as relevant as ever. (https://www.usenix.org/system/files/1311_05-08_mickens.pdf https://www.usenix.org/system/files/1311_05-08_mickens.pdf)