+static int ul_process_free(lua_State *L)
+{
+ struct lua_uloop_process *proc = lua_touserdata(L, 1);
+
+ /* obj.__index.__gc = nil , make sure executing only once*/
+ lua_getfield(L, -1, "__index");
+ lua_pushstring(L, "__gc");
+ lua_pushnil(L);
+ lua_settable(L, -3);
+
+ if (proc->r != LUA_NOREF) {
+ uloop_process_delete(&proc->p);
+
+ lua_getglobal(state, "__uloop_cb");
+ luaL_unref(state, -1, proc->r);
+ lua_remove(state, -1);
+ }
+
+ return 1;
+}
+
+static int ul_process_pid(lua_State *L)
+{
+ struct lua_uloop_process *proc = lua_touserdata(L, 1);
+
+ if (proc->p.pid) {
+ lua_pushnumber(L, proc->p.pid);
+ return 1;
+ }
+
+ return 0;
+}
+
+static const luaL_Reg process_m[] = {
+ { "delete", ul_process_free },
+ { "pid", ul_process_pid },
+ { NULL, NULL }
+};
+