Re: gtk in fork()ed process



On Wed, May 01, 2002 at 09:57:00AM +0200, Oliver Rauch wrote:
Hi.

I am forking a gtk-program to start an external program.
When the program start fails I want to display an error message
with gtk. The display routine shall be run in the child process
(I do not want to do any inter process comunication between
child and parent process to let the parent process display the
error message).

There happen very strange things when the child tries to
use gtk functions. I think gtk has to be re-initialized.
Is there a way to re-initialize gtk in the forked process?
Or what else do I have to do to use gtk in the child process?

Bye
Oliver
---end quoted text---
Well, if you don't at least wait4() the child process, you will let zombie process stay on your system until 
the main program dies, when init becomes parent of the zombies and clean them for you.
So, if you have to clean the process, you can do the error check by the return value of the child. Look:

pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage)

you can just call wait4 this way:
  int ret;
  wait4 (child_pid, &ret, 0, NULL);
and them, to check the return value,
  if (!WIFEXITED (ret) || WEXITSTATUS(ret)) {
    gtk....show_dialog..iguessthisisimplementedin2.0 ("Child process failed.");
  }

[]'s

PS: you can see the zombie processes with this code:
#include <unistd.h>
int main() {
  if (fork())
    sleep (60);
  return 0;
}
after running this, type: ps ux
search for you program name, and see, there will be two, and of them will be defunct/zombie, and when the 
main program exits, the another also exits.. (better way, will be cleaned.. hehe)
-- 
Marcelo R Leitner <mrl netbank com br>
ICQ #: 29966851



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