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

int main(int argc, char* argv[])
{
    int n=atoi(argv[1]);
    int i;
    char str[10], *res;
    int x;
    if(fork())
    {
        exit(0);
    }
    for(i=1; i<=n; i++)
    {
        if(n<=0)
        {
            exit(0);
        }
        else
        {


            FILE *fd=fopen("./pipe","r");

            while(1)
            {
                res=fgets(str,10,fd);
                if(res!=NULL)
                {
                    x=atoi(str);
                    printf("x: %d.\n", x);
                    system("ps -e -o pid,ppid,comm | grep readfromfifo");
                }
                sleep(15);
                exit(0);
            }
        }
    }

}
