kern/35377: process gets unkillable (-9) in "ttywai" state

Jean-Yves Lefort jylefort at brutele.be
Wed Nov 26 17:40:22 PST 2003


The following reply was made to PR kern/35377; it has been noted by GNATS.

From: Jean-Yves Lefort <jylefort at brutele.be>
To: freebsd-gnats-submit at FreeBSD.org, yuri at tsoft.com
Cc:  
Subject: Re: kern/35377: process gets unkillable (-9) in "ttywai" state
Date: Thu, 27 Nov 2003 02:35:19 +0100

 The problem should probably be fixed in the kernel, but I developed a
 workaround:
 
 --- start of ttyflush.c ---
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
 
 int
 main (int argc, char **argv)
 {
   int fd;
   int what = FWRITE;
 
   if (argc != 2)
     {
       printf("Usage: %s TERMINAL_DEVICE\n", argv[0]);
       exit(1);
     }
   
   fd = open(argv[1], O_RDONLY);
   if (fd == -1)
     {
       fprintf(stderr, "Unable to open terminal device %s: %s\n",
 	      argv[1], strerror(errno));
       exit(1);
     }
 
   if (ioctl(fd, TIOCFLUSH, &what) == -1)
     {
       fprintf(stderr, "ioctl() error: %s\n", strerror(errno));
       exit(1);
     }
 
   if (close(fd) == -1)
     {
       fprintf(stderr, "Unable to close terminal device: %s\n",
 	      strerror(errno));
       exit(1);
     }
 
   return 0;
 }
 --- end of ttyflush.c ---
 
 Compile it, and use it this way:
 
 1) Get the pseudo-terminal device of the offending process:
 
 	$ ps axww | grep irssi
 	87545  p1- IEs+   0:00.24 irssi
 	$
 
    In this case, it's /dev/ttyp1
 
 2) Flush the output queue, using the above program:
 
 	./ttyflush /dev/ttyp1
 
    That'll allow the process to exit.
 
 Regards,
 Jean-Yves Lefort
 
 -- 
 Jean-Yves Lefort
 
 jylefort at brutele.be
 http://lefort.be.eu.org/


More information about the freebsd-bugs mailing list