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

Re: fork()/exec() dumping



On Tue, 22 Jun 1999 11:18:50 -0700 (PDT), gtk-app-devel-list@redhat.com (Scott.) wrote:
> i need to spawn a non-gtk child from within a gtk app.
> 
> using the regular fork() and exec() to execute the other application
> results in a core dump. i remember some issues within gtk need to be
> addressed before the other program can be executed, but i'm not finding
> the info anywhere.
> 
> any help is appreciated. :)

This is becoming a FAQ. Never mind, here we go again:


  pid_t pid;
  int status;

  pid = fork();

  if(pid == -1)
    {
      perror("fork");
      exit(-1);
    }
  else if(pid == 0) /* child */
    {
      /* child code */
      system("nxterm -T 'Alloc' -n KMan -e man /usr/man/man3/Alloc.3");
      _exit(0); /* note the use of _exit() instead of exit();
      /* of course you can also use exec() over here */
    }
  else
    {
       /* parent code: just wait for the child to exit */
       /* you can also install a signal handler for SIGCHLD */
       waitpid(pid, &status, WUNTRACED); /* anti zombie */
    }


For more info on fork() and friends, read "Advanced programming in the
Unix environment" by Richard Stevens (Addison Wesley).


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




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