PDA

View Full Version : count processes



blob84
07-14-2011, 08:18 AM
hi, it is only an exercise,
how many processes are there in 30 seconds?
I think 30x9 processes?
It is impossible to count trying the code.


#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "/home/blob/Documenti/SO/err.h"

int main(void)
{
int i = 0;
int fd[2];
pid_t pid0, pid1, pid2, pid3, pid4, pid5;
pid_t pid6, pid7, pid8, pid9;
pid0 = fork();
pid1 = fork();
pid2 = fork();
pid3 = fork();
pid4 = fork();
pid5 = fork();
pid6 = fork();
pid7 = fork();
pid8 = fork();
pid9 = fork();
printf("hello\n");
sleep(30);
exit(0);
}

Salem
07-14-2011, 08:47 AM
> pid0 = fork();
Results in two processes.

> pid1 = fork();
Two processes call this, resulting in 4 processes.

Do you see where this is going?

Assuming that you don't actually run out of process table entries when running this fork-bomb.

Yarin
07-14-2011, 09:40 AM
hi, it is only an exercise,
how many processes are there in 30 seconds?
I think 30x9 processes?
It is impossible to count trying the code.
Your question is a little vague.
Are trying to count how processes were created as a result of your code (in which case, Salem answered)?
Or how many of your children are still running, at a certain point in time? If so, then google for a Linux IPC tutorial. That should help you out a lot.

Do you see where this is going?

Assuming that you don't actually run out of process table entries when running this fork-bomb.
Haha, it's always so funny seeing people do this.
But, actually, I don't think it would be so bad, I believe Linux has a safe-guard in place to detect and defuse fork bombing.

blob84
07-14-2011, 10:59 AM
ok it should be 2^10 processes, 1024

Yarin
07-14-2011, 11:09 AM
Correct, if unbridled, your process would spawn 1024 children/grandchildren. But your system may never even let it get that far. You'd have to try it and see :D