GLib.child_watch_add

function child_watch_add(priority: Number(gint), pid: GLib.Pid, function: GLib.ChildWatchFunc): Number(guint) {
    // Gjs wrapper for g_child_watch_add_full()
}
  

Sets a function to be called when the child indicated by pid exits, at the priority priority.

If you obtain pid from GLib.spawn_async or GLib.spawn_async_with_pipes you will need to pass #G_SPAWN_DO_NOT_REAP_CHILD as flag to the spawn function for the child watching to work.

In many programs, you will want to call GLib.spawn_check_exit_status in the callback to determine whether or not the child exited successfully.

Also, note that on platforms where GLib.Pid must be explicitly closed (see GLib.spawn_close_pid) pid must not be closed while the source is still active. Typically, you should invoke GLib.spawn_close_pid in the callback function for the source.

GLib supports only a single callback per process id.

This internally creates a main loop source using GLib.child_watch_source_new and attaches it to the main loop context using GLib.Source.prototype.attach. You can do these steps manually if you need greater control.

Since 2.4

priority

the priority of the idle source. Typically this will be in the range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.

pid

process to watch. On POSIX the positive pid of a child process. On Windows a handle for a process (which doesn't have to be a child).

function

function to call

Returns

the ID (greater than 0) of the event source.