Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I got an homework assignment to write a program that checks how many process a user can create (working in Ubuntu). I wrote the code which seems fine in theory. The problem is that when I run it, the system closes it and doesn't allow it to run after 3-5 seconds of work. The only reason I could think of is a protection embedded in Ubuntu. Is there a way to ignore this and run my program? I tried running it with root permissions as well but no luck.

How my program works: The 1st process fork() a new one and the father is put in wait to his son, then the newly created process creates another process (fork again) and waits for it and so on, until fork() fails and then I print a counter. Then everything existing so no zombies are left.

share|improve this question

closed as off topic by MadHatter, David Mackintosh, ewwhite, Skyhawk, mdpc Nov 14 '12 at 20:59

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2  
You really shouldn't edit your question like you did. Either delete it yourself or (even better) share your answer for future visitors. –  MDMarra Nov 14 '12 at 20:08
    
Change your algorithm (print "Process number [N] forking...") -- When the process table is full (or your program is killed) the last value of [N] printed is the limit. (or look at ulimit / /etc/security/limits.conf & see what the value is :-) –  voretaq7 Nov 14 '12 at 20:18
add comment

2 Answers 2

I think you want to look in /etc/security/limits.conf, you're likely hitting a defined nproc limit. The manpage for it describes the limits contained within. This is likely what's killing your attempted forkbombing.

share|improve this answer
add comment

You can look into ulimit -a. On my system (Ubuntu 12.04), it gives:

$ ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 29951
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 29951
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

When you look at "max user processes" (ulimit -u), you will see, that I can create at most 29951 processes.

share|improve this answer
add comment

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