6 ms·
The explanation is completely incorrect. The outer invocation of `yes` is never actually started. The reason is because the inner invocation is being used as an
by eridius 14y ago
The explanation is completely incorrect. The outer invocation of `yes` is never actually started. The reason is because the inner invocation is being used as an argument to the outer invocation, which means bash needs to know the entire output of the inner invocation before it even starts the outer invocation.
Instead, all you're seeing is bash thrashing as it tries desperately to capture all the output of `yes no` in-memory.
I expect you'd see the exact same behavior with echo `yes no`.
Now if you really want to screw over your machine, the classic bash fork bomb is
:(){ :|:& };:
- gjulianm 14y agoI've always preferred this tougher command to screw VMs I was going to delete. dd if=/dev/random of=/dev/sda Depending on how long does it run, you end up with a more or less screwed computer. It's funny to see how does the machine fall over when you invoke a simple 'cd' command after this.
- srl 14y agoBack when `/dev/mem` was a thing in default kernels (now you need a special config, or a module), I enjoyed `cat /dev/urandom > /dev/mem`. That would usually bork things pretty quickly, so then I would set random offsets with `dd`. Fun times.
- mikeash 14y agoSee also kmem Russian Roulette: https://twitter.com/shadowcat_mst/status/754107237269504 https://twitter.com/shadowcat_mst/status/754107237269504
- zx2c4 14y agoOr try this -- http://git.zx2c4.com/memory-hemlock/tree/slow-death.c http://git.zx2c4.com/memory-hemlock/tree/slow-death.c It picks a random device on your system -- ram, video, bios, etc -- and writes a random number of random bytes into it and then sleeps for a random amount of time. Last one standing lives.
- eridius 14y agoWhat's /dev/sda?
- gjulianm 14y agoOn Linux, the hard disk. This command, dd, copies data in bulk from /dev/random (a special device on *nix that outputs random bytes) to /dev/sda (your hard disk). That means it starts to overwrite your disk with trash, rendering the system unusable.
- eridius 14y agoI know what `dd` is. I just don't use Linux, so I'm not particularly familiar with the Linux-specific /dev entries. Thanks though.
- aroman 14y agoMost probably the storage device which is your HD.
- aidos 14y agoProbably your main drive.
- derleth 14y agoThe device file applications can use to access the first hard drive on most Linux systems. It provides raw access without filesystems or partitions. /dev/sda1 is the first partition on that drive, /dev/sda2 the second, and so on. /dev/sdb is the next hard drive, /dev/sdc the next after that; beyond /dev/sdz, the naming scheme is apparently dependent on the hardware driver in use: Going from /dev/sdz to /dev/sdaa is what happens in the default SATA and SCSI drives, up to /dev/sdzzz, at which point you apparently run into problems. [1] http://rwmj.wordpress.com/2011/01/09/how-are-linux-drives-named-beyond-drive-26-devsdz/ http://rwmj.wordpress.com/2011/01/09/how-are-linux-drives-na... [1] http://kerneltrap.org/mailarchive/linux-scsi/2010/9/20/6886603 http://kerneltrap.org/mailarchive/linux-scsi/2010/9/20/68866...
- huherto 14y agoAahhh. In the old days, we used this command just to mess with your workmates. while : do clear > /dev/tty sleep 5 done
- hp50g 14y agoWe wrote our own shell when I was at university (which was completely offensive, not at all obedient and generally no help whatsoever) and chsh'ed them if they left a terminal open :) (for ref, we had to do very naughty things to SunOS 4 to add it to /etc/shells)
- RyanGWU82 14y agoIt's not so funny when you do this accidentally, on a 2 TB disk full of user data, on a live production server, at 2AM on a Friday night... (The server was part of a MogileFS cluster so there were multiple copies of the data online. There was no data loss, not even any downtime. Still, it was scary as hell, and I spent all Saturday in the data center restoring the box.)
- xyos 14y agohow did you end up doing this accidentally?
- niggler 14y agoI've seen stranger: a redirect gone the wrong way $ foo < bar # runs command `foo`, reading from `bar` on stdin $ foo > bar # runs command `foo`, writing stdout to `bar` Writing `>` instead of `<` has resulted in many a blowup at 3 AM
- huherto 14y agoMy friend did this... rm * -i The system response was "-i not found" or something like that.
- ISL 14y agoI once discovered that apparently rm bob* has completely different behavior from rm bob * The above line of code successfully fixed a bug I'd been trying to find for weeks in source code in the same directory. When I rewrote it from scratch, the bug was gone.
- niggler 14y agorm -i is your friend
- 14y ago
- lucian303 14y agoI've always gone with the classic: rm -rf / However, sometimes that's protected so i switch: Lazy version: rm -rf /* Long version: rm -rf / --no-preserve-root But I do like your brute force random disk wipe method. I'll try that on the next vm that's gotta go.
- duaneb 14y ago> Now if you really want to screw over your machine, the classic bash fork bomb is `:(){ :|:& };:` Actually, you're wrong. At least on a mac (IIRC) it caps the process number so fork bombs just fill the console with errors. I'm sure you can get around it but that kind of defeats its simplicity. EDIT: I mean, don't get me wrong, it still really bogs your computer down, but you can still kill the parent bash process in a few seconds.
- ninetax 14y agoCrashed my machine running linux Mint. I couldn't Google it, so I had to try it. I don't know what I expected. Can someone explain how it works?
- gcr 14y agoBe careful running commands that you don't understand! I've been bitten by that before...
- duaneb 14y agoI don't know about linux (and I really should in this case as it's my 'field'), but at least on mac, you can restrict the number of child processes a process can spawn with `ulimit -u`: zooey:~ duane$ ulimit -u 709
- cheeseprocedure 14y agoThis is a very nice breakdown: http://www.cyberciti.biz/faq/understanding-bash-fork-bomb/ http://www.cyberciti.biz/faq/understanding-bash-fork-bomb/
- eridius 14y agoDepends on how much RAM you have. If your machine swaps everything out to disk before it hits the process limit, then you're pretty screwed anyway.
- jemfinch 14y agoIt's interesting that bash doesn't figure out the system's maximum command line length and either error or truncate if any single argument exceeds that length.
- ralph 14y agoIt would have to know the context; those limits don't apply for s=`foo`
- pstadler 14y ago`yes` is an excellent tool for simulating CPU load: CORES=4 for i in {1..$CORES}; do yes > /dev/null &; done