[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference azur::mcc

Title:DECmcc user notes file. Does not replace IPMT.
Notice:Use IPMT for problems. Newsletter location in note 6187
Moderator:TAEC::BEROUD
Created:Mon Aug 21 1989
Last Modified:Wed Jun 04 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:6497
Total number of notes:27359

2768.0. "Handling of stdout w/pipe and daemon process" by TOOK::SWIST (Jim Swist LKG2-2/T2 DTN 226-7102) Wed Apr 15 1992 09:39

    I have a process which starts a daemon process (of sorts).
    
    Users have noticed it is not possible to pipe the stdout from the
    parent process into another command.  (The pipe hangs after the
    parent process exits).
    
    The apparent reason is that after the fork, I do not close stdout
    in the subprocess just before the execve, so the open stdout is
    inherited by the detached process and the pipe hangs since the daemon
    process (by definition) outlives the parent.
    
    I know that closing fd's 0,1,and 2 is part of the protocol of setting
    up a daemon, but I don't really want to do that during our debug
    cycle since we have stuff printed on stdout which I'd like to go
    to either stderr ( the terminal that started the pipe to begin with )
    or /dev/console.   I've tried things like
    
                 dup2(1,2)  /* close stdout and redirect it to stderr */
    
    or 
    
                 fdreopen("/dev/tty", "w", stdout )
    
    or
    
    		 dup2(1, open("/dev/console", 0, 0) )
    
    in the subprocess and still hang.  Ultrix seems determined to keep
    stdout assign to the pipe.
    
    Any suggestions?
    
T.RTitleUserPersonal
Name
DateLines