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

main()
{
    int pid, pid2;
    pid = fork();
    if(pid > 0)
        exit(0);
    //barn under init..

    char str[10], *res; int x;
    FILE *fd=fopen("/home/me/Desktop/pipe","r");
    int i;

    if(!fork())
    {
     while(1) {

        res=fgets(str,10,fd);
        if(res!=NULL) {
            x=atoi(str);
            //printf("x: %d.\n", x);

            if(x > 0){
                for(i = 0; i < x; i++){

                    pid = fork();
                    if(pid == 0){

                        sleep(15);
                        exit(0);
                    }
                }
                exit(0);
            }
            else{
                printf("stopping...");
                exit(0);
            }


            system("ps -e -o pid,ppid,comm | grep readfromfifo");
            }

        }
        exit(0);
    }

    wait(0);
    sleep(15);
    exit(0);


}
