child-probe.dhover×98all
#!/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_probe

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.

child_probe
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.errno

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/errno.h.html, errno.h

Source

core/stdc/errno.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Alex Rønne Petersen@standardsISO/IEC 9899:1999 (E)
errno
:
(alias) child_probe.errno = int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.stdio

D header file for C99 <stdio.h>

pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h

Source

core/stdc/stdio.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly, Alex Rønne Petersen@standardsISO/IEC 9899:1999 (E)
stdio
:
(alias) child_probe.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
,
(alias) child_probe.fflush = int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trusted
fflush
;
import
(package) core
core
.
(package) core.stdc
stdc
.
(module) core.stdc.string

D header file for C99.

pubs.opengroup.org/onlinepubs/009695399/basedefs/string.h.html, string.h

Source

core/stdc/string.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseDistributed under the Boost Software License 1.0. (See accompanying file LICENSE)@authorsSean Kelly@standardsISO/IEC 9899:1999 (E)
string
:
(alias) child_probe.strcmp = int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.signal

D header file for POSIX.

Source

core/sys/posix/signal.d

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0@authorsSean Kelly, Alex Rønne Petersen@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
signal
:
(alias) child_probe.kill = int core.sys.posix.signal.kill(int, int) nothrow @nogc
kill
,
(alias constant) child_probe.SIGTERM = int core.stdc.signal.SIGTERM = 15
SIGTERM
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(package) core.sys.posix.sys
sys
.
(module) core.sys.posix.sys.wait

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly, Alex Rønne Petersen@standardsThe Open Group Base Specifications Issue 6, IEEE Std 1003.1, 2004 Edition
wait
:
(alias) child_probe.waitpid = int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogc
waitpid
,
(alias constant) child_probe.WNOHANG = int core.sys.posix.sys.wait.WNOHANG = 1
WNOHANG
;
import
(package) core
core
.
(package) core.sys
sys
.
(package) core.sys.posix
posix
.
(module) core.sys.posix.unistd

D header file for POSIX.

@copyrightCopyright Sean Kelly 2005 - 2009.@licenseBoost License 1.0.@authorsSean Kelly@standardsThe Open Group Base Specifications Issue 8, IEEE Std 1003.1, 2024 Edition
unistd
:
(alias) child_probe.fork = int core.sys.posix.unistd.fork() nothrow @nogc @trusted
fork
,
(alias) child_probe.getpid = int core.sys.posix.unistd.getpid() nothrow @nogc @trusted
getpid
,
(alias) child_probe.sleep = uint core.sys.posix.unistd.sleep(uint) nothrow @nogc @trusted
sleep
,
(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 @system
main
(int
(parameter) int argc
argc
, char**
(parameter) char** argv
argv
) @system nothrow @nogc
{ if (
(parameter) int argc
argc
!= 2 ||
int core.stdc.string.strcmp(scope const(char*) s1, scope const(char*) s2) pure nothrow @nogc
strcmp
(
(parameter) char** argv
argv
[1], "--run") != 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("SKIP: pass --run only for an approved 40-child experiment.\n");
return 0; } int[40]
(local variable) int[40] children
children
;
(alias) object.size_t = ulong
size_t
(local variable) ulong started
started
;
foreach (
(local variable) ulong i
i
; 0 ..
(local variable) int[40] children
children
.
(constant) ulong int[40].length = 40LU
length
)
{ const
(local variable) const(int) child
child
=
int core.sys.posix.unistd.fork() nothrow @nogc @trusted
fork
();
if (
(local variable) const(int) child
child
< 0)
{
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("fork: errno=%d\n",
int core.stdc.errno.__errno_location() nothrow @nogc ref @trusted
errno
);
break; } if (
(local variable) const(int) child
child
== 0)
{
uint core.sys.posix.unistd.sleep(uint) nothrow @nogc @trusted
sleep
(10);
noreturn core.sys.posix.unistd._exit(int) nothrow @nogc @trusted
_exit
(0);
}
(local variable) int[40] children
children
[
(local variable) ulong started
started
++] =
(local variable) const(int) child
child
;
}
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("parent=%d children-started=%zu\n",
int core.sys.posix.unistd.getpid() nothrow @nogc @trusted
getpid
(),
(local variable) ulong started
started
);
int core.stdc.stdio.fflush(shared(core.stdc.stdio._IO_FILE)* stream) nothrow @nogc @trusted
fflush
(null);
uint core.sys.posix.unistd.sleep(uint) nothrow @nogc @trusted
sleep
(7);
(alias) object.size_t = ulong
size_t
(local variable) ulong alive
alive
;
foreach (
(parameter) int child
child
;
(local variable) int[40] children
children
[0 ..
(local variable) ulong started
started
])
{ int
(local variable) int status
status
;
const
(local variable) const(int) result
result
=
int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogc
waitpid
(
(local variable) int child
child
, &
(local variable) int status
status
,
(constant) int core.sys.posix.sys.wait.WNOHANG = 1
WNOHANG
);
if (
(local variable) const(int) result
result
== 0)
{ ++
(local variable) ulong alive
alive
;
int core.sys.posix.signal.kill(int, int) nothrow @nogc
kill
(
(local variable) int child
child
,
(constant) int core.stdc.signal.SIGTERM = 15
SIGTERM
);
const
(local variable) const(int) reaped
reaped
=
int core.sys.posix.sys.wait.waitpid(int, int*, int) nothrow @nogc
waitpid
(
(local variable) int child
child
, &
(local variable) int status
status
, 0);
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("cleanup-child=%d wait=%d status=%d\n",
(local variable) int child
child
,
(local variable) const(int) reaped
reaped
,
(local variable) int status
status
);
} else
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("early-child=%d wait=%d status=%d\n",
(local variable) int child
child
,
(local variable) const(int) result
result
,
(local variable) int status
status
);
}
int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogc
printf
("alive-at-sample=%zu of %zu; cleanup-complete\n",
(local variable) ulong alive
alive
,
(local variable) ulong started
started
);
return
(local variable) ulong started
started
==
(local variable) int[40] children
children
.
(constant) ulong int[40].length = 40LU
length
? 0 : 1;
}