Re: Pointers and spawning processes with glib



On 10 December 2010 11:36, Rupert Swarbrick <rswarbrick gmail com> wrote:
> Hi,
>
> I'm writing something using glib's process spawning features. A silly
> example of what I'm doing might look something like this:
>
>
>
> I've just been browsing through the code in glib's gspawn.c and I
> *think* that, since it works by calling fork() then exec(), the strings
> pointed to by argv are copied on the line with the
> g_spawn_async_with_pipes() call.

Since spawn creates a new process, the argv and envp arrays must be
copied because the new process cannot access the address space of this
process.

>
> My first question is, is this right? That is, am I safe to write
>
>  g_free (path)

yes

>
> just before the error-checking code, for example? (Yes, I know that
> would be silly, but I want to understand what's going on :-) )
>
> If so, I have a second question/suggestion. Should the documentation for
> the async spawning functions have an explicit comment saying that the
> memory is copied? Maybe developers with more experience with fork() and
> exec() see that this is obvious but I, for one, didn't!
>

It is pretty obvious it must be copied, even on windows where
fork/exec doesn't exist.

Cheers
Lex


> Thanks,
>
> Rupert
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
>


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