fork()/exec() round 2



I've got the following code: (it's short)

/* begin parent snippet - pretty straight-forward fork/exec code */
  my_pid = fork();
  switch (my_pid) {
  case -1:
    g_error("Can't create new process\n");
    break;
  case 0:
    g_print("I'm the child\n");
    execl("child", "child", NULL);
    g_print("This should not print.\n"); /* it doesn't. :) */
    break;
  default:
    /* GUI -- do nothing special, just continue running */
    g_print("parent: pid = %d\nparent: child_pid = %d\n",getpid(),my_pid);
    break;
  }
/* end parent snippet */

/* begin complete main() from child */
  int i;
  for (i=0; i<5; i++) {
    printf("child: pid = %d\nchild: ppid = %d\n",getpid(),getppid());
    sleep(2);
  }

  printf("exiting child\n");
  exit(0);
/* end complete main() from child */

The parent code is actually in a button-click callback, but that should
make no difference.  Running top shows that when the child exits, it is
left as a zombie process until the parent (in this case my GUI containing
the button) exits.

This doesn't make sense to me.  Shouldn't the child process *completely*
disappear when it calls exit(0)?  What's the key morsel of info I'm
missing here?

Dan "apparently missing the obvious"
 ____    Kressin   ____   .-----------------------------------. 
/___ \____________/ __ \  | dkressin@acm.org                  |
    \  \    /      /  \ | | Lead Programmer/Analyst           |
 ___/ __\/\/rench_ \__/ | | University of Wisconsin - Oshkosh |
\____/            \____/  | www.mio.uwosh.edu/~kressd11/      |
                          `-----------------------------------'




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]