Path: utzoo!attcan!uunet!littlei!intelisc!joel From: joel@intelisc.UUCP (Joel Clark) Newsgroups: comp.unix.wizards Subject: Sun child termination. Keywords: fork exec stdin Message-ID: <347@intelisc.UUCP> Date: 16 Sep 88 18:22:51 GMT Organization: Intel Scientific Computers, Beaverton, OR Lines: 58 Perhaps someone could explain some odd behavior in the following to programs: ######################## Cut here for foo2.c ############################## #include 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 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@intelisc.COM Intel Scientific Computers 15201 SW Greenbrier Parkway Beaverton, Or 97006 (503) 629-7732