From nobody@FreeBSD.org  Wed Feb 27 06:45:52 2002
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id B2B6637B405
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 27 Feb 2002 06:45:51 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.6/8.11.6) id g1REjpQ05597;
	Wed, 27 Feb 2002 06:45:51 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200202271445.g1REjpQ05597@freefall.freebsd.org>
Date: Wed, 27 Feb 2002 06:45:51 -0800 (PST)
From: Yuri Victorovich <yuri@tsoft.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: process gets unkillable (-9) in "ttywai" state
X-Send-Pr-Version: www-1.0

>Number:         35377
>Category:       kern
>Synopsis:       process gets unkillable (-9) in "ttywai" state
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 27 06:50:00 PST 2002
>Closed-Date:    Mon Feb 21 15:14:16 UTC 2011
>Last-Modified:  Mon Feb 21 15:14:16 UTC 2011
>Originator:     Yuri Victorovich
>Release:        FreeBSD 4.4 STABLE
>Organization:
Optima Inc
>Environment:
FreeBSD s1.optima-hyper.com 4.4-RELEASE FreeBSD 4.4-RELEASE #0: Tue Sep 18 11:57:08 PDT 2001     murray@builder.FreeBSD.org:/usr/src/sys/compile/GENERIC  i386

>Description:
minicom (from ports) was controlling through serial port another
process. minicom's original parent was _su run under sshd connection.
After ssh client on the other end was killed minicom stays in "ttywai"
condition. After _su got killed minicom still stays with PPID=1 (see
ps auxwj output below).

======================================
USER   PID %CPU %MEM   VSZ  RSS  TT  STAT STARTED      TIME COMMAND          USER   PID  PPID  PGID   SESS JOBC STAT  TT       TIME COMMAND
nobody   926 99.0  6.1 16044 15540  p0- RN    9:03PM 733:42.84 /usr/local/sbin/ nobody   926     1   926 c165d6c0    0 RN    p0- 733:42.84 /usr/local/sbin/
root     1  0.0  0.1   544  320  ??  ILs   2:34PM   0:00.01 /sbin/init --    root     1     0     1 c11c9f80    0 ILs   ??    0:00.01 /sbin/init --
root     2  0.0  0.0     0    0  ??  DL    2:34PM   0:00.21  (pagedaemon)    root     2     0     0 c03e1640    0 DL    ??    0:00.21  (pagedaemon)
root     3  0.0  0.0     0    0  ??  DL    2:34PM   0:00.00  (vmdaemon)      root     3     0     0 c03e1640    0 DL    ??    0:00.00  (vmdaemon)
root     4  0.0  0.0     0    0  ??  DL    2:34PM   0:00.89  (bufdaemon)     root     4     0     0 c03e1640    0 DL    ??    0:00.89  (bufdaemon)
root     5  0.0  0.0     0    0  ??  DL    2:34PM   0:10.49  (syncer)        root     5     0     0 c03e1640    0 DL    ??    0:10.49  (syncer)
root    63  0.0  0.8  2468 2004  ??  Ss    2:34PM   0:06.89 named            root    63     1    63 c11fb840    0 Ss    ??    0:06.89 named
root    69  0.0  0.3  1056  792  ??  Is    2:34PM   0:00.00 /usr/sbin/inetd  root    69     1    69 c1204c40    0 Is    ??    0:00.00 /usr/sbin/inetd 
root    71  0.0  0.3   976  716  ??  Ss    2:34PM   0:00.20 /usr/sbin/cron   root    71     1    71 c12047c0    0 Ss    ??    0:00.20 /usr/sbin/cron
root    73  0.0  0.6  2216 1628  ??  Is    2:34PM   0:01.11 /usr/sbin/sshd   root    73     1    73 c1207b00    0 Is    ??    0:01.11 /usr/sbin/sshd
root    76  0.0  0.5  1652 1268  ??  Ss    2:34PM   0:02.67 /usr/local/apach root    76     1    76 c12078c0    0 Ss    ??    0:02.67 /usr/local/apach
nobody    78  0.0  0.5  1688 1312  ??  I     2:34PM   0:00.02 /usr/local/apach nobody    78    76    76 c12078c0    0 I     ??    0:00.02 /usr/local/apach
nobody    79  0.0  0.5  1688 1312  ??  I     2:34PM   0:00.02 /usr/local/apach nobody    79    76    76 c12078c0    0 I     ??    0:00.02 /usr/local/apach
nobody    80  0.0  0.5  1688 1312  ??  I     2:34PM   0:00.02 /usr/local/apach nobody    80    76    76 c12078c0    0 I     ??    0:00.02 /usr/local/apach
nobody    81  0.0  0.6  2060 1444  ??  I     2:34PM   0:00.02 /usr/local/apach nobody    81    76    76 c12078c0    0 I     ??    0:00.02 /usr/local/apach
nobody    82  0.0  0.5  1700 1320  ??  I     2:34PM   0:00.02 /usr/local/apach nobody    82    76    76 c12078c0    0 I     ??    0:00.02 /usr/local/apach
root    83  0.0  0.8  2504 2056  ??  Ss    2:34PM   0:01.95 sendmail: accept root    83     1    83 c1226e80    0 Ss    ??    0:01.95 sendmail: accept
root    98  0.0  0.2   904  520  ??  Is    2:34PM   0:00.00 moused -p /dev/p root    98     1    98 c1226700    0 Is    ??    0:00.00 moused -p /dev/p
root   108  0.0  0.4  1652  976 con- I+    2:34PM   0:00.02 sbin/pipsecd     root   108     1     6 c11c9e40    0 I+   con-   0:00.02 sbin/pipsecd
root   116  0.0  0.3  1196  876  v0  Is    2:34PM   0:00.01 login -p root    root   116     1   116 c127f9c0    0 Is    v0    0:00.01 login -p root
root   117  0.0  0.3   948  656  v1  Is+   2:34PM   0:00.00 /usr/libexec/get root   117     1   117 c127fe80    0 Is+   v1    0:00.00 /usr/libexec/get
root   118  0.0  0.3   948  656  v2  Is+   2:34PM   0:00.00 /usr/libexec/get root   118     1   118 c127fc80    0 Is+   v2    0:00.00 /usr/libexec/get
root   119  0.0  0.3   948  656  v3  Is+   2:34PM   0:00.00 /usr/libexec/get root   119     1   119 c1226940    0 Is+   v3    0:00.00 /usr/libexec/get
root   120  0.0  0.3   948  656  v4  Is+   2:34PM   0:00.00 /usr/libexec/get root   120     1   120 c127f940    0 Is+   v4    0:00.00 /usr/libexec/get
root   121  0.0  0.3   948  656  v5  Is+   2:34PM   0:00.00 /usr/libexec/get root   121     1   121 c127fb40    0 Is+   v5    0:00.00 /usr/libexec/get
root   122  0.0  0.3   948  656  v6  Is+   2:34PM   0:00.00 /usr/libexec/get root   122     1   122 c127fac0    0 Is+   v6    0:00.00 /usr/libexec/get
root   123  0.0  0.3   948  656  v7  Is+   2:34PM   0:00.00 /usr/libexec/get root   123     1   123 c127fa80    0 Is+   v7    0:00.00 /usr/libexec/get
root   124  0.0  0.2   944  624  ??  I     2:34PM   0:00.00 /usr/libexec/get root   124     1     1 c11c9f80    0 I     ??    0:00.00 /usr/libexec/get
root   125  0.0  0.5  2852 1352  ??  Is    2:34PM   0:00.00 /usr/local/sbin/ root   125     1   125 c1253300    0 Is    ??    0:00.00 /usr/local/sbin/
nobody   127  0.0  2.3  6668 5996  ??  S     2:34PM   0:06.74 (squid) (squid)  nobody   127   125   125 c1253300    0 S     ??    0:06.74 (squid) (squid)
nobody   128  0.0  0.2   860  400  ??  Is    2:34PM   0:00.00 (unlinkd) (unlin nobody   128   127   128 c128fe00    0 Is    ??    0:00.00 (unlinkd) (unlin
root   129  0.0  0.4  1328  944  v0  I+    2:34PM   0:00.03 -csh (csh)       root   129   116   129 c127f9c0    1 I+    v0    0:00.03 -csh (csh)
nobody   163  0.0  0.5  1696 1316  ??  I     2:59PM   0:00.02 /usr/local/apach nobody   163    76    76 c12078c0    0 I     ??    0:00.02 /usr/local/apach
root   260  0.0  0.6  1840 1580  p2- IE    4:52PM   0:03.38 minicom          root   260     1   260 c1207800    0 IE    p2-   0:03.38 minicom
root   303  0.0  0.3   940  656  ??  Ss    5:39PM   0:00.60 syslogd -s       root   303     1   303 c15632c0    0 Ss    ??    0:00.60 syslogd -s
root   422  0.0  0.3  1016  780  ??  I     6:32PM   0:00.00 cron: running jo root   422    71    71 c12047c0    0 I     ??    0:00.00 cron: running jo
root   423  0.0  0.2   628  428  ??  Is    6:32PM   0:00.00 /bin/sh -c /usr/ root   423   422   423 c15a5ac0    0 Is    ??    0:00.00 /bin/sh -c /usr/
root   424  0.0  3.6  9840 9124  ??  S     6:32PM   0:01.35 /usr/local/bin/p root   424   423   423 c15a5ac0    0 S     ??    0:01.35 /usr/local/bin/p
root   425  0.0  0.8  2524 2064  ??  Is    6:32PM   0:00.02 /usr/sbin/sendma root   425   422   425 c165da00    0 Is    ??    0:00.02 /usr/sbin/sendma
root  1856  0.0  0.8  2320 1920  ??  S     9:08AM   0:00.20 sshd: yuri@ttyp0 root  1856    73    73 c1207b00    0 S     ??    0:00.20 sshd: yuri@ttyp0
yuri  1857  0.0  0.2   636  452  p0  Is    9:08AM   0:00.01 -sh (sh)         yuri  1857  1856  1857 c16c6280    0 Is    p0    0:00.01 -sh (sh)
root  1859  0.0  0.4  1336  984  p0  D     9:08AM   0:00.06 _su (csh)        root  1859  1857  1859 c16c6280    1 D     p0    0:00.06 _su (csh)
root  1940  0.0  0.1   440  304  p0  R+    9:25AM   0:00.00 ps -auxwj        root  1940  1859  1940 c16c6280    1 R+    p0    0:00.00 ps -auxwj
root     0  0.0  0.0     0    0  ??  DLs   2:34PM   0:00.09  (swapper)       root     0     0     0 c03e1640    0 DLs   ??    0:00.09  (swapper)
root  1941  0.0  0.4  1336  984  p0  RV    9:25AM   0:00.00 _su (csh)        root  1941  1859  1859 c16c6280    1 RV    p0    0:00.00 _su (csh)
>How-To-Repeat:
see description
>Fix:
reboot unfortunately
>Release-Note:
>Audit-Trail:

From: Jean-Yves Lefort <jylefort@brutele.be>
To: freebsd-gnats-submit@FreeBSD.org, yuri@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@brutele.be
 http://lefort.be.eu.org/
State-Changed-From-To: open->feedback 
State-Changed-By: jh 
State-Changed-When: Fri Jan 14 13:45:49 UTC 2011 
State-Changed-Why:  
Can you still reproduce this on a supported release? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=35377 
State-Changed-From-To: feedback->closed 
State-Changed-By: jh 
State-Changed-When: Mon Feb 21 15:10:31 UTC 2011 
State-Changed-Why:  
Feedback timeout from submitter. The bug still exists according to bde@ 
but old tty layer had a workaround (comcontrol(8) configurable timeout). 
(Thanks to bde@ for explaining all this.) 

I think it's better to close this and submit new PR(s) for the new tty 
layer bugs if necessary. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=35377 
>Unformatted:
