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

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

        // while(1) {
    res=fgets(str,10,fd);
    if(res!=NULL) {

      x=atoi(str);
      printf("x: %d.\n", x);

    }
    sleep(1);
  //}

        switch(pid = fork()){

        case -1:
        perror("Fork error\n");
        exit(1);

        case 0:
             for(i = 1; i <=x; i++){

            switch(pid = fork()){
                case -1:
                perror("Fork error\n");
                exit(1);

                case 0:
                    sleep(15);

            }
    }
    exit(0);
    default:
       wait(0);
       system("ps -e -o pid,ppid,comm | grep uppg1");

}




return 0;
}
