Re: Glibmm, Giomm and daemon program



On Sun, 8 Nov 2009 13:16:03 +0100
Tomasz Jankowski <tomcioj gmail com> wrote:
> Hello!
> 
> I'm working on daemon program, which use Glibmm and Giomm. I have to
> call few functions from Glib and Gio before I run fork(), so at the
> beginning of main function I call Glib::init() and Gio::init():
> 
> main()
> {
> Glib::init ();
> Gio::init ();
> 
> // Here I use Glib::OptionContext etc
> 
> fork ();
> 
> // rest of code
> }
> 
> I'd like to know if Glib::init() and Gio::init() do some "weird"
> things (like opening files) in background, which may cause problems,
> when I fork program.

I suspect you will be OK but this is one of those occasions where it is
probably best to try it and see.  You will certainly run into problems
however if you fork() from the thread in which GTK+ is running after
calling gtk_main().

To fork() after the main loop is running I always start a new thread to
dispatch the new process and fork() from that.  Of course, that also
means (since it will thus become a multi-threaded program) that you can
only call async-signal-safe functions after the fork() and before the
call to exec*().  This in turn means you must call all non
async-signal-safe functions which are needed to prepare for an exec()
before the fork() and not after, but given that all modern fork()
implementations provide copy on write, that is not problematic. (You
probably know all that but I thought it worth mentioning.)

Chris


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