Ok, I have this program:
/* prog2.c */
Code:#include <unistd.h> #include <stdio.h> main(int argc, char **argv) { int i,j,count; int pid; int indent=0; if (argc!=2) { printf("syntax: %s count\n",argv[0]); exit(0); } count=atoi(argv[1]); printf("each child processed is displayed in the format\ parent(iteration)->child\n"); printf("shell( ) -> %d\n",getpid()); for (i=0;i<count;i++) { pid = fork(); if (pid == 0) { indent++; for (j=0; j<indent;j++) printf("\t\t"); sleep(3); printf("%d(%d) -> %d\n",getppid(),i,getpid()); } else sleep(3); } }
I am trying to get it to produce exactly n child processes when I execute it like this:
prog2 n
Any ideas?
Thanks
[code][/code]tagged by Salem



LinkBack URL
About LinkBacks


