Re: Forking from Gtk



Hi,

2008/7/7 G Hasse <gorhas raditex se>:
I have a small demo app. This works on FreeBSD but I can't
get to work on Linux.

I tried your code on my Ubuntu machine and it works fine. I had to add:

// needed for fork()
#include <unistd.h>

// needed for umask()
#include <sys/types.h>
#include <sys/stat.h>

near the top, but that's all. You have the child doing
gtk_main_quit(), which I don't think is necessary. It works fine
without that line.

I know that in Linux setsid will fail
if the child has the same session_id as the parent. So on
Linux you must fork twice.

I don't think that's correct. Linux setsid() will fail if the calling
process is already a process group leader, the same as freebsd. So you
can't setsid() from your main process, you have to do it from a child.

Other posters have said "don't use fork()" and they are correct. You
should not make any gtk_*() calls from the child process.
g_timeout_*() for simple cases, and g_thread*() for complex ones are
much better.

There are however legitimate uses for fork(). I do this myself when I
have to run a complex command-line program from a GUI front end. I
think fork() is quite reasonable in this case.

You could also consider popen() and friends if you want to capture
program output to display in a window.

John



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