fork, tee and a defunct process

From: Eiler, James A. (James.Eiler@alcoa.com)
Date: Wed May 28 2003 - 11:11:03 EDT


Hi all,

I don't believe this is solely a Tru64 problem, but any insight would be
appreciated!

I've got a C program that forks. I run the program from a shell script and
pipe the output to a log file. A simplified version of the C code (hello.c)
is as follows:

#include <stdio.h>
#include <unistd.h>

main( )
{
   if( fork( ) == 0 ) {
      printf( "Entering child's code\n" );
      fflush( stdout );

      while( 1 ) {
         printf( "This is a test!\n" );
         fflush( stdout );
         sleep( 5 );
      }
   }
   else {
      printf( "Parent exiting, PID = %d\n", getpid( ) );
      exit( 0 );
   }
}

The command I'm issuing to get this running is:

# hello | tee hello.log&

Stuff gets logged into the log file as expected, but an unexpected "side
effect" is a defunct process:

# ps -ef | grep defunct
eilerja 34718 34734 0.0 - pts/2 0:00.00 <defunct>

When I look for the parent process, it looks like it's tee:

# ps -ef | grep 34734
eilerja 34718 34734 0.0 - pts/2 0:00.00 <defunct>
eilerja 34734 32901 0.0 11:05:48 pts/2 0:00.00 tee hello.log

Any suggestions on how to eliminate the defunct process?

THANKS!

Jim



This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 10:49:20 EDT