PTY's

John-Michael Wiley wileyjm at turing.cs.rpi.edu
Wed Jul 25 01:09:08 AEST 1990


I am trying to write a process that sits between the csh and the 
terminal (See code below). The routine openpty simply opens
up the master and slave side of a psuedo-terminal using the 
flags O_RDWR | O_NDELAY. 

Whenever I run the code I get the message

Stopped (tty input)

and then I get my normal shell prompt. I know it is not the child's
prompt because I have the command number in my prompt. Can anyone tell
me what I am doing wrong? Please email responses to
    wileyjm at turing.cs.rpi.edu

Thanks in advance,
J.M. Wiley

/***********************************************************************/
/* #includes and globale vars declared .... */

main(argc, argv)
  int argc;
  char *argv[];
  
{
  char out_buff[MAXLINE];
  char in_buff[MAXLINE];
  char program[128];
  fd_set rd, wr, ex;
  int width = getdtablesize();
  int code;
  
  
  openpty(&master, &slave, masterPath, slavePath);
  
  /*** Now start the child process                          ***/
  child_pid = fork();
  switch(child_pid) {
  case -1 :
  perror("Can't create a new process");
  exit(-1);
 case 0:
  close(master);
  if((dup2(slave, 0) == -1)  ||
     (dup2(slave, 1) == -1) ||
     (dup2(slave, 2) == -1)) {
    perror("Clef Trying to Dupe child");
    exit(-1);
  }
  if(slave > 2) close(slave);
  sprintf(program, "/bin/csh");
  execlp( program,program, NULL);
  perror("Trying to exec");
  break;
 case 1:  
  close(slave);
  while(1)  {   
    FD_ZERO(&rd);
    FD_SET(master, &rd); 
    FD_SET(0, &rd); 
    code = select(width, &rd, (fd_set *) NULL, (fd_set *) NULL, NULL);
    if(code < 0) {
      perror("Select");
      exit(-1);
    }
    
    if(FD_ISSET(master, &rd)) {
      if((num_read = read(master, out_buff, MAXLINE)) == -1) { 
	perror("Reading child output");
	exit(-1);
      } else 
      write(1,out_buff, num_read);
    } else if(FD_ISSET(0, &rd)) {
      num_read = read(0, in_buff, MAXLINE);
      if(num_read < 0) {
	perror("Reading stdin");
	exit(-1);
      } else 
      write(master, in_buff, num_read);
    }
  }
}
J.M. Wiley               ------            wileyjm at turing.cs.rpi.edu

Go Heels'                       



More information about the Comp.unix.questions mailing list