3

So I was playing around with a live disk experiment (using an external HHD as a live disk) and I made a script that made 9,023 directories on my desktop before I could stop it. Being the noob I am I ran this command to clean up my mess:

rm -rf Desktop 

And then made a new folder called Desktop in my home directory. My computer worked fine for a few seconds then everything but my mouse froze. Thankfully it was all on a live disk so nothing was lost but I would like to know what I actually did.

I tried to google "ubuntu deleted desktop directory" and other variations, but all I got was people trying to get rid of it, not bring it back.

EDIT: there was some interest in the fork bomb that I ran. Don't laugh:

while true; do
for i in a; do
declare b=b+1
mkdir "$b" 
done
done

I kind of guessed what it would do but I was used to working with Python where I could kill it quickly before it got too far out of control.

To anyone else who reads this at some point in the future: don't run that fork bomb, it makes a mess.

P.S. Before you say how dumb it was for me to do that in the first place please note that I was in a live disk that was set aside just for the purpose of doing stuff like that so I can learn.

  • So you ran a fork bomb, deleted your desktop, and now you want us to fix it? Do I understand you correctly? grins We all started somewhere. Seriously, reinstall. – KGIII Oct 31 '15 at 20:54
  • I already fixed it I would just like to know what exactly I did. And if the freeze was from something I did. – unknown Oct 31 '15 at 20:58
  • 2
    Ah - okay. You deleted your desktop, your desktop environment (from the sounds of things). Then you ran a command that spawns new folders or files (called a fork bomb) until it ate all the available resources. That means the computer freezes because there are no more resources to use. Always, always, know the commands and what they do before running them - search engines will help you find each specific command. – KGIII Oct 31 '15 at 21:00
  • @KGIII Could you please convert the upvoted comment to an answer so that schmucks like me who go around hunting for unanswered questions don't have to look at this one any more? ;-) (And I'll upvote if you drop me a note and it's a good one too!) – Fabby Oct 31 '15 at 21:05
  • @KGIII I did it the other way around. I made the folders then deleted the desktop. – unknown Oct 31 '15 at 21:08
5

It's good that you did this with a Live USB or you'd have lost some data, almost certainly. Cleaning up after that would have been a huge waste of time.

First, you ran what's known as a fork bomb. A fork bomb is a simple, often obfuscated, command that will keep spawning new processes, folders, or files until it fills up disk space, eats CPU cycles, or consumes all the RAM. This results in the computer freezing because it has no more resources to give.

Second, you deleted your DE (desktop environment) which is what you see, it's the graphics that you interact with, the windows that you have open (sort of - there's a window manager but we'll skip that for now). Basically, you killed everything that you could click on.

It's good to learn. Use your favorite search engine before typing in commands into the terminal. Always, always know what the command does before pressing ENTER. I can not emphasize that enough. There are people who will intentionally mislead you. The terminal is a potentially powerful tool. It's your greatest tool in your toolbox but, like all tools, it must be wielding carefully.

If you'll tell us what the command was, for the fork bomb, we might be able to digest that and tell you exactly what it did and why. You seem like a curious sort so maybe you'd also like to learn that?


Edit:

You've now included the code for your fork bomb. I'll include this for the next person to come along. If you look at it and parse the logic, you can see that it's saying that so long as a condition exits (is true) then do something (make an enumerated directory) and, because there's nothing telling it to stop (a loop), it will keep on going until the resources are consumed, RAM is eaten up, or until there's just some sort of collision that makes things freeze up. (This could be all sorts of things like a memory leak but that's probably not a factor here.)

From the sounds of things, or from what I'm reading, it appears like you did a pretty good job. This is a clear warning for others, to not run your code (you should add that to your post with the edit function or someone else can if you want). It was creative. I don't think I've ever seen it done quite that way but the theory is pretty much the same with all of them. Again, for others, this can be hidden in obfuscated code or code you simply may not understand if you don't know how to parse Perl (as an example). This is a fine example of what not to do.

I dare say, you should finish installing it and have some more fun. Just keep good backups.

  • Question edited to include the fork bomb. I was not mislead by an Internet troll, I made up the commands from the bits and pieces of bash that I already knew. Thanks for the help! – unknown Nov 1 '15 at 3:16
  • @unknown That's pretty clever work. I updated my answer for you - well, not so much for you but for the people who follow and may read this at a latter date. You should edit your question (one last time) to include a note to clearly explain that people should not run that code as it is a bad idea. While you may think that nobody would do that, well, someone just might - even after reading your post. It's clever and good work, by the way. I've not seen it done quite like that but that's certainly valid code. Check my edit if you want and, if you get a chance, change your question a little. – KGIII Nov 1 '15 at 3:27
0

Rebooting, re-creating the desktop directory from a virtual console, and then logging into the desktop again should fix it. Your computer crashed either because you ran a fork bomb or because your desktop directory disappeared while your desktop environment was trying to use it, but in either case my suggested fix will repair it (although you've lost whatever was on your desktop).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.