-2

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.

2
  • 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, 2012 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, 2012 at 20:18

2 Answers 2

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.

1

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.

Not the answer you're looking for? Browse other questions tagged .