Sun child termination.

Joel Clark joel at intelisc.UUCP
Sat Sep 17 04:22:51 AEST 1988


Perhaps someone could explain some odd behavior in the following to programs:

########################   Cut here for foo2.c  ##############################

#include <fcntl.h>
main()
{
   int pid;

       pid = fork();
       if (pid == 0){
           execl("./foo");
       }
       sleep(40);
}
#######################   Cut here for foo.c  ###############################

main()
{
    char c;
    int i;
        printf("start foo\n");
        i = read(0,&c,1);
	printf("read %d chars\n",i);
        write(1,&c,1);
        for(;;) {
            i = read(0,&c,1);
            write(1,&c,1);
	    if ( i != -1){	
		printf("input %d chars\n",i);
	    }
        }
}

######################   Cut here   ########################################

On a Sun 3/50 running Sun OS 3.5  the child program terminates with no 
message, at the read on stdin, as soon the parent terminates.  If the child 
does not read stdin, it survives.   If stdin is closed before the read, read
returns -1. 

On Sys V/386 R3.0  the child does not terminate and is able to read any input
the shell does not get.  ( i.e. type chars and <cr> quickly so that the child
gets chars while the shell is processing input from previous line.)

This code is much reduced from a large system that uses several daemon process
fileservers.

Why is the child terminating??   How can I work around this so it behaves
on the Sun and it does on Sys V/386  OR AT LEAST returns an error.


Joel Clark					joel at intelisc.COM
Intel Scientific Computers
15201 SW Greenbrier Parkway
Beaverton,  Or  97006

(503) 629-7732



More information about the Comp.unix.wizards mailing list