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

main()
{
    if(fork())
  {
      exit(0);
  }
    wait(0);
    sleep(1);
  char str[10], *res; int x;
  pid_t pid;
  FILE *fd=fopen("/home/me/Desktop/pipe","r");
int i;


  while(1)
{

    res=fgets(str,10,fd);
    if(res!=NULL) {
      x=atoi(str); printf("\nx: %d.\n", x);
      int a = x;
      system("ps -e -o pid,ppid,comm | grep uppg1");

      while(a>0)
      {
          a--;
          pid = fork();
          if(pid==0)
          {
              sleep(15);
                exit(0);
          }
          //wait(0);
      }
      wait(0);
      if(x<=0)
      {
          exit(0);
      }


    }
    sleep(1);
  }


}
