简体   繁体   中英

Gnome shell GLib async process become defunct

I'm writing a gnome shell extension and running a bash script with

let [, pid, , , ] = imports.gi.GLib.spawn_async(null, args, null, GLib.SpawnFlags.DO_NOT_REAP_CHILD, null);

which works, however after running a few times I'm able to see

ps aux | grep pid

the processes are there, and marked as defunct. Is this normal? Should I be cleaning up these processes? Or this is normal behavior?

The description of GLib.spawn_async() does say to call GLib.spawn_close_pid() but the description of that says:

On some platforms, notably Windows, the GLib.Pid type represents a resource which must be closed to prevent resource leaking. GLib.spawn_close_pid is provided for this purpose. It should be used on all platforms, even though it doesn't do anything under UNIX.

My system is ubuntu, should I be calling spawn_close_pid() ?

From the documentation for G_SPAWN_DO_NOT_REAP_CHILD :

the child will not be automatically reaped; you must use g_child_watch_add() yourself (or call waitpid() or handle SIGCHLD yourself), or the child will become a zombie.

So what's happening is normal: the child process is being spawned, doing something, exiting and becoming defunct — but no parent process is reaping it. Dead processes hang around until reaped so that the parent process can check their exit status.

You need to either stop using the GLib.SpawnFlags.DO_NOT_REAP_CHILD flag (in which case GLib will watch for the child process exiting and will reap it automatically); or add a child watch handler yourself using g_child_watch_add() and reap the defunct process in the GChildWatchFunc callback using g_spawn_close_pid() .

There's an example in this question or another here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM