fork()ing problem

Stelios Bounanos sb at dial.pipex.com
Sat Dec 8 02:32:02 EET 2001


On Sat, Dec 08, 2001 at 01:12:59AM +0200, Andreou Al. 
 <ee4299 at ee.teiath.gr> was rumoured to have said:

> 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...)
> 

Isws na yparxei ontws kapoio limit, des ti leei to ulimit. Epishs
mporei apla to systhma soy na mh shkwnei oses processes 8es. Opws kai
na' xei, prepei na piaseis kai thn periptwsh poy h fork() epistrefei -1.
Apo to errno mporeis na ma8eis meta giati apetyxe.


> Eyxaristw, Alexandros.
> 


Rgds,
/-sb.

-- 

Stelios Bounanos <sb at dial.pipex.com>
  ..............7500000 years later:
  The Ultimate Answer is 42.
  (next mail will give the Question)



More information about the Linux-greek-users mailing list