- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
That would make an excellent interview question if you want to be nasty...
Admin
Can we please keep the politics out of these articles?
Admin
Admin
TRWTF is Bruce's abysmal spelling.
Admin
Admin
Admin
I do not think it does what you think it does.
In the parent process, fork(2) returns -1 on failure and the child process's pid on success. In the child process, it returns 0. Thus, what this program does is create a series of child processes, each of which immediately exit. However, if it manages to fill the process table or hit the process limit (RLIMIT_NPROC), it will simply spin until it can fork again, because fork(2) will return -1, which evaluates to true.
The simplest example is this:
which will reproduce exponentially, because each child process will also fork an infinite series of child processes, each of which will fork an infinite series of child processes, and so on ad nauseam.
So perhaps TRWTF is not Bruce's abysmal spelling, as I wrote earlier, but the number of readers who think they know C.
Addendum (2014-04-14 13:08): ETA: I read your code as "while (fork());" instead of "while (1) fork();". Forget I ever said anything.
Admin
You might as well have written
because your program will just fork once and then exit, then the child process will fork once and then exit, etc. At some point, PIDs will roll around and a process might get lucky and start a few more dynasties. The chance of this happening is greatly reduced if PID randomization is enabled, and zero on FreeBSD where PIDs below 100 are reserved for kernel processes (except for 1, which is reserved for init(8)). This may also be the case on Linux - I can't be bothered to check.
(hint: on success, fork(2) returns the PID of the child process)
Admin
Actually, i += fork() kills the fork bomb. Most likely, the child PID is going to be > 100 so each thread creates one child thread and goes out of the loop. You end up with just a 100 deep stack; that too with each thread doing nothing except one child thread spawn and quit.
Admin
Ah, I failed to take the increment into account; i is effectively a bounded generation counter.
Admin
Steve's example and yours are the same. As per C99 & C++98, "If control reaches the end of main without encountering a return statement, the effect is that of executing return 0".
When the child process is forked, it is still within that while infinite loop and is never going to exit the while loop to hit the return statement, implicit or explicit.
Admin
Indeed they are. I somehow read it as "while (fork());" instead of "while (1) fork();". My bad.
Admin
The real WTF is why Ray bought beers for the sysadmins. I mean, it's not like they did anything...
(CAPTCHA: praesent - I guess it was Ray's way of buying them a little praesent...)
Admin
Yes, you are.
(CAPTCHA: appellatio - I am so lucky - I met this girl at the bar who's really into appellatio...)
Admin
And is this somehow unusual?
Admin
While your point is well taken, let's apply a reality filter here. Let's consider what would happen when the bomb script was run on the test server and it locked up tighter'n...something that's really, really tight:
"Hey, the test server's down!" "Define 'down'." "Uhhh...I can't log in to a command window..." "Can you ping it?" "Uhhh...yup, sure can". "Reboot it". "Yeah, but that's the third time this morning". "Yeah, well, it's been doing that lately. Dunno what's wrong with it. We always get the crappy machines for test. I think that's a 386 running NT 3.1. If they'd just give us decent test machines...(blah-blah-blah)"
...and thus the bomb script would have eventually been cleared for release, without actually being run successfully. I mean, c'mon, what could go wrong..?
(CAPTCHA: abbas - that guy is so ripped he's got an abbas...)
Admin
This is government. Your tax dollars at play...
Admin
"Who are you?" "No one to be trifled with". "I must know". "Get used to disappointment".
Admin
Sure - but not out of the comments. :-)
(CAPTCHA: uxor - I went me to Eee-gypped and saw me them ol' Temples at Uxor..!)
Admin
Admin
Admin
No, that's just a boring old fork bomb. The original code, that's interesting for an interview.
Admin
Admin
The editors often submit articles from a smartphone without any sorting of spell checking, which is TRWTF.
Admin
It only takes 127 beers for Fezzik to go down.
Admin
That envelope of paper clips was too big to fail!
Admin
This article is obviously commentary on how Bush invaded Kenya for oil and to find Obama's real birth certificate.
Admin
Because I can. The last line of this WTF uses the phrase 'going forward'. Can I ask what this means? If, as I am loathe to suggest, it is supposed to mean 'from this point on', or simply 'from now' or the sci-fi freakout of 'in the future' (god forbid) this begs the question.
What might the logical alternative to 'going forward' actually be? If it`s what I think it is please confirm what Mr Einsteins reaction was when it was explained to him.
Admin
been there, done that, on the acedemic services VAX. quick fix, blow the logfile from the console. not quite a hero, not quite a zero. but I ended up splitting the joined drive I was carving students out of in the end, and that was heroic for uptime.
Admin
You don't post pieces on a highly read site if you can't write perfect english, "writer".
Admin
Just like "compose" versus "comprise" - another common error.
Admin
If I ever have to write underhanded C code, I'll try to remember swapping the comparison and the increment in a for statement, because I sure didn't notice it until nitPicker pointed it out. Playing fast and loose with i++ vs ++i adds to the underhandedness.
Admin
Admin
Needs more Helmut, or Heinrick, or whateverthefuck his name is.
Admin
Admin
Neither was the case here.
Admin
I got about 50 monitors donated out of that. Good show!
Admin
Done!
Admin
The point was to spawn 2**100 threads and kill the system. 100 threads don't even cut it close.
Admin
Admin
Why? Is the truth too challenging for you?
Admin
You'd probably still have those paperclips because what you'd do is receive as many memos paperclipped together as you sent.
Admin
Admin
One more thing to write down in your exorcise book.
Admin
Recursions of Unusual Size? I don't think they exist.
CAPTCHA - Jugis: when Fezzik's looking for a rhyme and starts making up words
Admin
Admin
Don't try to bait a flamewar.
“If you think health care is expensive now, wait until you see what it costs when it's free.” ― P.J. O'Rourke
Admin
Admin
If the server's down, hit the power switch.
Admin
Yes, you are right, i made i mistake in the for loop, the project was done over 10 years ago, so i don't have the original code anymore.
but using the code as part of an interview is actually a good idea.
and the execution of a for loop depends on the optimization level you use. if switched off the loop gets executed even without modification of i within it.
PS: you are free to use my wtf mistake in the "not working fork bomb"