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

main()
{
    if(fork())
        exit(0);

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

    }
}
