SUMMARY wait funtion

From: ABDON TREMOLS <abdon.t_at_usa.net>
Date: Tue, 18 Aug 1998 13:03:55 -0600 (MDT)

Hello,

Thanks for your examples and suggestions, specially to
( sorry if I forgot someone):

Kurt Carlson <snkac_at_java.sois.alaska.edu>
John Hascall <john_at_iastate.edu>
Larry Griffith <larry_at_garfield.wsc.mass.edu>
Lars Bro <lbr_at_dksin.dk>

The general idea is to get a copy of Unix Network
Programing by W. Richard Stevens.

This is a listing of one of the examples I received:

        pid_t cpid;
        pid_t wpid;
        int wst;
        extern int errno;

        switch (cpid = fork()) {
            case -1: /* error */
                fprintf(stderr, "fork failed: %s\n", strerror(errno));
                exit(1);
            case 0: /* child (new process) */
                execl("/bin/ps", "ps", "ax", NULL);
                fprintf(stderr, "exec failed: %s\n", strerror(errno));
                exit(1);
            default: /* parent (original proc)
*/
                while ((wpid = wait(&wst)) != -1) {
                        if (wpid == cpid) {
                                /* child just started above died */
                                break;
                        } else {
                                /* some other child died??? */
                        }
                        /* could use WIFEXITED/WEXITSTATUS/etc here to
                         * look at child's exit status in 'wst' variable
                         * (see "man wait" for details)
                         */
                }
        }


Thanks again,

Abdon


  
 







____________________________________________________________________
Get free e-mail and a permanent address at http://www.netaddress.com/?N=1
Received on Tue Aug 18 1998 - 19:04:57 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:38 NZDT