Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!brl-tgr!gwyn From: gwyn@brl-tgr.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: exit() from child and status in parent wait() Message-ID: <10078@brl-tgr.ARPA> Date: Fri, 19-Apr-85 20:34:49 EST Article-I.D.: brl-tgr.10078 Posted: Fri Apr 19 20:34:49 1985 Date-Received: Mon, 22-Apr-85 00:33:17 EST References: <2530@drutx.UUCP> Organization: Ballistic Research Lab Lines: 30 > if((pid = fork()) == NULL) { Failure is indicated by -1 not by NULL (which is 0). > perror(); perror() requires a (char *) argument to be printed. > execl("cmd","cmd","arg",0); The last argument should be (char *)0. > perror(); (See previous perror note; also, exec failure is most often handled in the parent branch of the fork.) > exit(16); No! exit() flushes the stdio buffers, but does not affect the same buffered data in the parent branch. Use _exit(127) instead. (_exit() is like exit() without any cleanup actions.) > while((wid = wait((unsigned int *)rtn_code)) != pid); Here is the main problem; you need to pass the ADDRESS of rtn_code to wait(). This is &rtn_code, not what you have written (which asks for the CONTENTS of rtn_code to be interpreted as an address). As a matter of style, I suggest also that the null statement ; be written on a separate line. > if(rtn_code == 16) { ANY nonzero rtn_code should be treated as unsuccessful execution of the child. The low 8 bits of rtn_code are a general class of termination (0 for normal exit) and the next lowest 8 bits are the returned exit status code (for normal exit; they encode other things for other classes of termination). Only a normal exit with 0 exit status code should be considered successful.