#!/usr/bin/env dub
/+ dub.sdl:
name "android-research-child-probe"
platforms "linux"
dflags "-betterC"
targetPath "build"
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}
+/
/**
Bounded E8 payload. Default invocation never forks; --run starts 40 children
which exit after ten seconds even if the parent dies. The parent samples after
seven seconds, terminates only its own surviving children, and reaps them.
See ../index.md#current-target-experiments. Run only with owner approval.
*/
module (module) child_probeBounded E8 payload. Default invocation never forks; --run starts 40 children
which exit after ten seconds even if the parent dies. The parent samples after
seven seconds, terminates only its own surviving children, and reaps them.
See ../index.md#current-target-experiments. Run only with owner approval.
child_probe;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.errnoD header file for C99.
pubs.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html, errno.h
Source
core/stdc/errno.d
errno : (alias) child_probe.errno = int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stdioD header file for C99 <stdio.h>
pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h
Source
core/stdc/stdio.d
stdio : (alias) child_probe.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf, (alias) child_probe.fflush = int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trustedfflush;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stringD header file for C99.
pubs.opengroup.org/onlinepubs/009695399/basedefs/string.h.html, string.h
Source
core/stdc/string.d
string : (alias) child_probe.strcmp = int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogcstrcmp;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.signalD header file for POSIX.
Source
core/sys/posix/signal.d
signal : (alias) child_probe.kill = int core.sys.posix.signal.kill(int, int) nothrow @nogckill, (alias constant) child_probe.SIGTERM = int core.stdc.signal.SIGTERM = 15SIGTERM;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(package) core.sys.posix.syssys.(module) core.sys.posix.sys.waitD header file for POSIX.
wait : (alias) child_probe.waitpid = int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogcwaitpid, (alias constant) child_probe.WNOHANG = int core.sys.posix.sys.wait.WNOHANG = 1WNOHANG;
import (package) corecore.(package) core.syssys.(package) core.sys.posixposix.(module) core.sys.posix.unistdD header file for POSIX.
unistd : (alias) child_probe.fork = int core.sys.posix.unistd.fork() nothrow @nogc @trustedfork, (alias) child_probe.getpid = int core.sys.posix.unistd.getpid() nothrow @nogc @trustedgetpid, (alias) child_probe.sleep = uint core.sys.posix.unistd.sleep(uint) nothrow @nogc @trustedsleep, (alias) child_probe._exit = noreturn core.sys.posix.unistd._exit(int) nothrow @nogc @trusted_exit;
extern(C) int int child_probe.main(int argc, char** argv) nothrow @nogc @systemmain(int (parameter) int argcargc, char** (parameter) char** argvargv) @system nothrow @nogc
{
if ((parameter) int argcargc != 2 || int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogcstrcmp((parameter) char** argvargv[1], "--run") != 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("SKIP: pass --run only for an approved 40-child experiment.\n");
return 0;
}
int[40] (local variable) int[40] childrenchildren;
(alias) object.size_t = ulongsize_t (local variable) ulong startedstarted;
foreach ((local variable) ulong ii; 0 .. (local variable) int[40] childrenchildren.(constant) ulong int[40].length = 40LUlength)
{
const (local variable) const(int) childchild = int core.sys.posix.unistd.fork() nothrow @nogc @trustedfork();
if ((local variable) const(int) childchild < 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("fork: errno=%d\n", int core.stdc.errno.__errno_location() nothrow @nogc ref @trustederrno);
break;
}
if ((local variable) const(int) childchild == 0)
{
uint core.sys.posix.unistd.sleep(uint) nothrow @nogc @trustedsleep(10);
noreturn core.sys.posix.unistd._exit(int) nothrow @nogc @trusted_exit(0);
}
(local variable) int[40] childrenchildren[(local variable) ulong startedstarted++] = (local variable) const(int) childchild;
}
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("parent=%d children-started=%zu\n", int core.sys.posix.unistd.getpid() nothrow @nogc @trustedgetpid(), (local variable) ulong startedstarted);
int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trustedfflush(null);
uint core.sys.posix.unistd.sleep(uint) nothrow @nogc @trustedsleep(7);
(alias) object.size_t = ulongsize_t (local variable) ulong alivealive;
foreach ((parameter) int childchild; (local variable) int[40] childrenchildren[0 .. (local variable) ulong startedstarted])
{
int (local variable) int statusstatus;
const (local variable) const(int) resultresult = int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogcwaitpid((local variable) int childchild, &(local variable) int statusstatus, (constant) int core.sys.posix.sys.wait.WNOHANG = 1WNOHANG);
if ((local variable) const(int) resultresult == 0)
{
++(local variable) ulong alivealive;
int core.sys.posix.signal.kill(int, int) nothrow @nogckill((local variable) int childchild, (constant) int core.stdc.signal.SIGTERM = 15SIGTERM);
const (local variable) const(int) reapedreaped = int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogcwaitpid((local variable) int childchild, &(local variable) int statusstatus, 0);
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("cleanup-child=%d wait=%d status=%d\n", (local variable) int childchild, (local variable) const(int) reapedreaped, (local variable) int statusstatus);
}
else
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("early-child=%d wait=%d status=%d\n", (local variable) int childchild, (local variable) const(int) resultresult, (local variable) int statusstatus);
}
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf("alive-at-sample=%zu of %zu; cleanup-complete\n", (local variable) ulong alivealive, (local variable) ulong startedstarted);
return (local variable) ulong startedstarted == (local variable) int[40] childrenchildren.(constant) ulong int[40].length = 40LUlength ? 0 : 1;
}