Return to the Project 1 Page

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

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

  /*
   * This ignores a signal generated by job control shells like tcsh 
   * preventing them from interfering with our shells
   */
  sigemptyset (&blocked);
  sigaddset (&blocked, SIGTTOU);
  sigaddset (&blocked, SIGTTIN);
  sigprocmask(SIG_BLOCK, &blocked, 0);

  ppid = getpid();

  if (!(cpid=fork()))
  {
    setpgid(0,0);
    tcsetpgrp (0, getpid());
    execl ("/bin/vi", "vi", NULL);
    exit (-1);
  }
  
  if (cpid < 0)
    exit(-1);

  setpgid(cpid, cpid);
  tcsetpgrp (0, cpid);

  waitpid (cpid, NULL, 0);

  tcsetpgrp (0, ppid);

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