lua-users home
lua-l archive

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

On Mon, 09 Nov 2009 18:59:18 +0100
Florian Weimer <> wrote:
> If you want to call fork() from Lua code, you have to disable the GC
> so that finalization doesn't occur both in the child and the parent.
> If this happens in a library routine, you need to make sure that the
> code composes with callers needing to disable GC as well.  And this
> means that you need some sort of counter.

Could you please elaborate on this a bit? I'm having difficulty
understanding the problem. I'm building an application that uses
nixio.fork() to create worker processes. I haven't noticed any problem
using fork() yet.

Here is nixio's implementation of fork():

static int nixio_fork(lua_State *L) {
    pid_t pid = fork();
    if (pid == -1) {
        return nixio__perror(L);
    } else {
        lua_pushinteger(L, pid);
        return 1;

Dead simple. It does nothing with the Lua GC, and as I said above, I
don't see why it should.

If it's application code that must be careful using this with reqard
to the GC, then I'd really appreciate a head's up.