Function glib::source::child_watch_add [−][src]
pub fn child_watch_add<F>(pid: Pid, func: F) -> SourceId where
F: FnMut(Pid, i32) + Send + 'static,
Expand description
Adds a closure to be called by the main loop the returned Source
is attached to when a child
process exits.
func
will be called when pid
exits
Sets a function to be called when the child indicated by pid
exits, at a default priority, G_PRIORITY_DEFAULT
.
If you obtain pid
from spawn_async()
or g_spawn_async_with_pipes()
you will need to pass SpawnFlags::DO_NOT_REAP_CHILD
as flag to
the spawn function for the child watching to work.
Note that on platforms where GPid
must be explicitly closed
(see g_spawn_close_pid()
) pid
must not be closed while the
source is still active. Typically, you will want to call
g_spawn_close_pid()
in the callback function for the source.
GLib supports only a single callback per process id.
On POSIX platforms, the same restrictions mentioned for
g_child_watch_source_new()
apply to this function.
This internally creates a main loop source using
g_child_watch_source_new()
and attaches it to the main loop context
using g_source_attach()
. You can do these steps manually if you
need greater control.
pid
process id 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.