#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

main()
{
    if(!fork())
    {
        char str[10], *res;
        int x,i;
        FILE *fd=fopen("./pipe","r");
        while(1)
        {
            res=fgets(str,10,fd);
            if(res!=NULL)
            {
                x=atoi(str);
                printf("\nAdding %d children under INIT\n",x);
                //    printf("x: %d.\n", x);
                              system("ps -e -o pid,ppid,comm | grep uppg1");
            }

            for(i = 0; i++; i<x)
            {
                if(!fork())
                {
                    sleep(0);
                    exit(0);
                }
                system("ps -e -o pid,ppid,comm | grep uppg1");
                //   printf("grr");
		if(i == x){
		printf("Stopping daemon.");
		break;
exit(1);
}
            }
            sleep(15);
            system("ps -e -o pid,ppid,comm | grep uppg1");
        }
  //          sleep(15);  
  }
    exit(0);
    system("ps -e -o pid,ppid,comm | grep uppg1");

}

