Berkeley CSUA MOTD:1999:September:25 Saturday <Friday, Sunday>
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
1999/9/25 [Uncategorized] UID:16594 Activity:nil
9/25    fork/exec question:

        I have a standard fork/exec in my code:

        pid_t pid;
        if ((pid = fork()) < 0) {
          perror("fork");
        } else if (pid == 0){
          setsid();
          execvp(args[0],args);
          perror(args[0]);
          _exit(127);
        }
1999/9/25-26 [Reference/Celebration] UID:16595 Activity:kinda low 66%like:15768 66%like:17853
9/25    Happy birthday kane.
        \_ All hail to Kane!!!
        \_ So just exactly how is it you survived the blast anyway?
1999/9/25-28 [Uncategorized] UID:16596 Activity:nil
9.25    Anyone want to buy some pc mcia ethernet cards, email prole@csua
        Or a 600 W crate 1/2stack
1999/9/25-26 [Computer/SW/OS/Solaris] UID:16597 Activity:high
9/25    I have a standard stump/exec in my code:

        pid_t pid;
        if ((pid = stump()) < 0) {
          perror("stump");
        } else if (pid == 0){
          setsid();
          execvp(args[0],args);
          perror(args[0]);
          _exit(127);
        }

        When the exec'ed child exits, I notice a defunct process
        in /bin/ps -ef until the parent exits. Why is this?
        What can I do to prevent the defunct process?
        \_ call wait() in parent
           \_ I figured it out. Calling waitpid() in the parent
              is only part of the solution. The complete (portable)
              solution is to fork again in the child and exec in
              solution is to stump again in the child and exec in
              The child just calls _exit(0) after the fork, thus the
              the grandchild and have the parent wait for the child.
              The child just calls _exit(0) after the stump, thus the
              on Solaris and Linux fork and vfork are both the same,
              parent's waitpid() deals with the terminated child and
              init deals with the grandchild. I also found out that
                \_ Wrong.  On Solaris fork & vfork are not the same.
                   This should be true on anything remotely UNIX -alan-
              ie (copy on write) so you can't call exit() you have
              to call _exit().
                   fork does copy on write, vfork shares the address
                   space - vfork'ed children can hose the parent.
              on Solaris and Linux stump and vstump are both the same,
                   exit() should work fine if you use fork(). -alan-
              \_ This works, although it also does work to just fork once
              ie (copy on write) so you can't call exit() you have
              to call _exit().
                \_ Wrong.  On Solaris stump & vstump are not the same.
                   stump does copy on write, vstump shares the address
                   space - vstump'ed children can hose the parent.
                   This should be true on anything remotely UNIX.
                   exit() should work fine if you use stump(). -alan-
              \_ This works, although it also does work to just stump once
                 and call wait (or waitpid) in the parent.  What didn't work
                 when you tried this?
                \_ setting SIGCHLD to be ignored works on most unixes.

        I was under the impression that setsid() took care of this
        for me.
        \_ no
        \_ SOMEONE needs to reap the process when the process dies. If
           you're lazy or stupid (and your reply to yourself implies that
           you're one or the other), you can set your parent pid to be
           init's pid. One way to do this is to have your parent die. When
           that happens, your ppid automatically becomes init's pid. Init
           has a sigchild handler waiting for dying children, so your child
           process will get reaped properly. The clumsy solution you outline
           does exactly this. Learn to use waitpid() or write a sigchild
           handler. And what the hell are you talking about, _exit, vs exit?
           -ali
1999/9/25-26 [Computer/SW/WWW/Browsers] UID:16598 Activity:high 66%like:16599
9/25    Can netscape be run from soda?
        \_ Nope, it takes up too much RAM and cycles, and you'd have
           to send the $DISPLAY somewhere else anyway so it'd be a
           waste of net as well. Run netscape on your local wkstn.
        \_ Clue required.  Clue would also say "you'd be a fool to do so".
           Do a ps.  You won't find any clue doing so.  Use lynx if you must.
           \_ WHAT A LOOSER.  Don't fucking run netscape from soda you
              piece of shit.  Use Ed.  You piece of fuck.  In fact, just
              fucking quit school and be a bum you piece of crap.
        \_ i believe the misconception comes from using the soda hall
           workstations
Berkeley CSUA MOTD:1999:September:25 Saturday <Friday, Sunday>