kern/52490: ^T'ing a zombie causes 'calcru: negative time' messages

Jilles Tjoelker jilles at
Tue May 20 10:50:10 PDT 2003

>Number:         52490
>Category:       kern
>Synopsis:       ^T'ing a zombie causes 'calcru: negative time' messages
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 20 10:50:08 PDT 2003
>Originator:     Jilles Tjoelker
>Release:        FreeBSD 5.1-BETA i386
System: FreeBSD 5.1-BETA FreeBSD 5.1-BETA #10: Mon May 12 15:30:54 CEST 2003 jilles at i386

It occurs on 4.8-RELEASE and many older 4.x versions as well.
When ^T'ing (ttyinfo) a zombie, calcru() is called and logs a 'negative time'
message. To achieve this, only zombies must be in the foreground process group
of the terminal.
Compile and run the negtime program. Pressing ^T after it has printed the
message 'done' causes a log message 'calcru: negative time...'. (It may be
necessary to do stty status ^t beforehand.)
A patch (against 4-STABLE) is attached which prevents calcru() from being
called on zombies from ttyinfo(). I don't know in what process states calcru()
may be called exactly, but for the rest of /sys/kern it's only used for
accounting, exiting and getrusage() and therefore cannot be called on zombies.
(Perhaps this is or should be documented somewhere.)

--- negtime.c begins here ---
/* Copyright (C) 2001 by Jilles Tjoelker */

#include	<sys/types.h>
#include	<stdio.h>
#include	<signal.h>
#include	<unistd.h>

main(int argc, char *argv[])
    int pid,pgid;

    if (argc != 1)
	fprintf(stderr, "Usage: %s\n", argv[0]);

    switch (pid=fork())
	case 0:
	    if (setpgid(pid,pid)==-1)
		perror("Error in setpgid()");
	    if (tcsetpgrp(0,pid)==-1)
		perror("Error in tcsetpgrp()");

	case -1:
	    fprintf(stderr, "Error in fork().\n");

    return 0;

/* vim:ts=8:cin:sw=4:kp=man\ -S3\:2\:9\:1\:4\:5\:6\:7\:8\:n
--- negtime.c ends here ---

--- ttyinfo_zombie.patch begins here ---
--- /usr/src/sys/kern/tty.c.orig	Mon Mar 11 02:32:31 2002
+++ /usr/src/sys/kern/tty.c	Sun Jan 19 21:40:16 2003
@@ -2323,7 +2323,7 @@
 		    pick->p_stat == SRUN ? "running" :
 		    pick->p_wmesg ? pick->p_wmesg : "iowait");
-		if (pick->p_flag & P_INMEM) {
+		if (pick->p_flag & P_INMEM && pick->p_stat != SZOMB) {
 			calcru(pick, &utime, &stime, NULL);
 			/* Print user time. */
--- ttyinfo_zombie.patch ends here ---


More information about the freebsd-bugs mailing list