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

main()
{

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

    if(pid==0)
    {

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

            while(1)
            {

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


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

                    system("ps -e -o pid,ppid,comm|grep readfromfifo");
                    sleep(2);
                    exit(0);
                    }
                    exit(0);
                }
                sleep(1);


            }
        }
        //sleep(3);
        exit(0);
    exit(0);
    }
wait(0);
}
