Return to the Lab #4 Page

#include <stdio.h>
#include <signal.h>
#include <stddef.h>
#include <sys/wait.h>

int main()
{
  int count;
  int status;
  int cpid;
  char buf[256];
  char title[256];
  sigset_t blocked;

  for (count=0; count < 3; count++)
  {
    if (!(cpid=fork()))
    {
      setpgid (0,0);
      tcsetpgrp (0, getpid());
      sprintf (title, "%d", count);
      execl ("/usr/X/bin/xterm", "xterm", "-title", title, NULL);
      exit (-1);
    }
  
    if (cpid < 0)
      exit(-1);
  }

  wait (&status);

  while (1)
  {
    memset (buf, 0, 256);
    fgets (buf, 256, stdin);
    puts ("ECHO: ");
    puts (buf);
    puts ("\n");
  }
}