use of libcore.util.MutableInt in project XobotOS by xamarin.
the class ProcessManager method watchChildren.
/**
* Loops indefinitely and calls ProcessManager.onExit() when children exit.
*/
private void watchChildren() {
MutableInt status = new MutableInt(-1);
while (true) {
try {
// Wait for children in our process group.
int pid = Libcore.os.waitpid(0, status, 0);
// Work out what onExit wants to hear.
int exitValue;
if (WIFEXITED(status.value)) {
exitValue = WEXITSTATUS(status.value);
} else if (WIFSIGNALED(status.value)) {
exitValue = WTERMSIG(status.value);
} else if (WIFSTOPPED(status.value)) {
exitValue = WSTOPSIG(status.value);
} else {
throw new AssertionError("unexpected status from waitpid: " + status.value);
}
onExit(pid, exitValue);
} catch (ErrnoException errnoException) {
if (errnoException.errno == ECHILD) {
// Expected errno: there are no children to wait for.
// onExit will sleep until it is informed of another child coming to life.
waitForMoreChildren();
continue;
} else {
throw new AssertionError(errnoException);
}
}
}
}
Aggregations