fork, tee and a defunct process

From: Eiler, James A. (James.Eiler_at_alcoa.com)
Date: 05/28/03

  • Next message: susan james: "username character limit"
    Date: Wed, 28 May 2003 11:11:03 -0400
    To: tru64-unix-managers@ornl.gov
    
    

    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


  • Next message: susan james: "username character limit"