fork()ing problem

Andreou Al. ee4299 at ee.teiath.gr
Sat Dec 8 01:14:02 EET 2001


Exw to akoloy8o programma:
---
ee4299 at nemesis:~/prod > cat fork2.c
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

int main(int argc, char **argv) {
        unsigned long times;
        char *s;

        times=atol(argv[1]);
        printf("Hi, my name is %s (%d) and I am a parent what will spawn %d
bastards.\n", argv[0], getpid(), atoi(argv[1]));
        while (times--) {
                if (!fork()) {
                        /* I am child. I print my pid and die dramatically.
*/
                        printf("%d => %d\n", getppid(), getpid());
                        exit(1);
                }
        }

        return 0;
}
ee4299 at nemesis:~/prod >
---

to opoio to egrapsa gia na dw ti ginetai otan yparxei ta pids ftasoun sto
65535, kai gia na dw ligo tis fork(), getpid(), getppid().

Exw twra to e3hs problhma: otan to trexw me mia parametro (estw 1000), pote
de ftanw sto 1000o pid, alla panta stamataw kapoy pio prin (p.x.: 11550 =>
12333), otan xrhsimopoiw megalous ari8mous (1000 kai panw peripoy) gia th
metablhth times.

Exete kapoia idea toy ti mporei na ginetai? Yparxei kapoio limit sta spawned
childs mias process? (de nomizw...)

Eyxaristw, Alexandros.





More information about the Linux-greek-users mailing list