fork()ing with gtk



I'm writing a GTK program that forks a child, which then execs ls, sending
its output to the write end of a pipe for the parent to read. I've tested
the exact same lines of code in a short non-gtk program and it works just
fine, but my gtk program crashes with sigsegv and sigpipe caught. Below is
what the comp.windows.x had to say on the subject. It wasn't very useful
since GTK is at a higher level than this. I searched the gtk-list
archives, and the few postings there on the subject had no answer either.
Any suggestions?

Subject: 172)  How do I fork without hanging my parent X program?

        An X-based application which spawns off other Unix processes which 
continue to run after it is closed typically does not vanish until all of
its 
children are terminated; the children inherit from the parent the open X 
connection to the display. 
        What you need to do is fork; then, immediately, in the child
process, 
                close (ConnectionNumber(XtDisplay(widget)));
to close the file-descriptor in the display information. After this do
your 
exec. You will then be able to exit the parent.
        Alternatively, before exec'ing make this call, which causes the
file 
descriptor to be closed on exec.
                (void) fcntl(ConnectionNumber(XDisplay), F_SETFD, 1);


/----------------------------------------------------------\
| pretzelgod                 | epgilles@olemiss.edu        |
| (Eric Gillespie, Jr.)      | epg@pretzelnet.cx           |
|---------------------------<*>----------------------------|
| "That's the problem with going from a soldier to a       |
|  politician: you actually have to sit down and listen to |
|  people who six months ago you would've just shot."      |
|  --President John Sheridan, Babylon 5                    |
\----------------------------------------------------------/




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