ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I just decide to try something I haven't done in linux for a long time. We were having a discussion at work about solaris vs. linux thread management. Somebody was arguing that a forking program gone bad in solaris would bring the system to a halt while in linux it would eventually kill them all and the system would be fine. So I wrote a small program I call nastyfork to test this theory:
Code:
#include <sys/types.h>
#include <unistd.h>
#include <limits.h>
int main(void)
{
unsigned long i;
for (i=0;i<=LONG_MAX;i++)
{
if(!fork())
{
break;
}
}
return 0;
}
When I ran this on the 2.4 kernel the same basic thing happen that happened in solaris, the machine became unusable. So I was bored this morning and I brought nastyfork back out and ran it on my 2.6.1 kernel with the preemtible kernel enabled. To my surprise it runs happily up to the point where linux says it can't fork anymore, and although my processor usage reads 100% and I can't run anything because "bash: fork: Resource temporarily unavailable" my GUI interface is still VERY responsive, which is a step in the right direction.
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304
Rep:
i'm running that code right now on 2.4.23-ck1 with the desktop low latency patches
that i don't really understand, but the system is plenty responsive. how long
should it take to die?
it takes about 10 seconds to get up to 14,000 something tasks, and then adds
no more. cpu usage says 100% as i'm typing this.
I tried this simpler forkbomb.c, which could be even a little nastier because it doesn't stop after LONG_MAX.
Code:
#include <unistd.h>
int main()
{
for(;;) fork();
return 0;
}
I tried it on the latest 2.4 kernel (2.4.24) without any patches, and it even made me use the power switch. On 2.6.1 I can type this post as if nothing is happening. "top" on another xterm doesn't update its display anymore though...
ive not done much testing but video capture seems to be rubbish in a preemptible 2.6.0 even in single user mode audio and video go out of sync almost immediatly where they dont in 2.4.22, but this could be due to new v4l/bttv stuff when i have time i'll test it properly.
btw i know 2.4.22 and 2.6.0 have security problems, and im not using them anymore
Ya, should be easy to get a 2.6.1 kernel with and without the peremptible part and see if it makes a difference. Perhaps the bttv modules weren't update..
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304
Rep:
Quote:
Originally posted by Hko I tried this simpler forkbomb.c, which could be even a little nastier because it doesn't stop after LONG_MAX.
Code:
#include <unistd.h>
int main()
{
for(;;) fork();
return 0;
}
I tried it on the latest 2.4 kernel (2.4.24) without any patches, and it even made me use the power switch. On 2.6.1 I can type this post as if nothing is happening. "top" on another xterm doesn't update its display anymore though...
i tried that one, and i couldn't start an tasks, and i couldn't really exit any either.
i exited x, and couldn't get a prompt back. i typed df, on a different terminal,
no response. i could suspend a task, but not end one. i hit reset after about
10 minutes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.