Supporting running the killall command under Shadow would give users some flexibility on how processes are killed. e.g. if they wish a tor process to be gracefully shut down via SIGTERM near the end of the simulation instead of killed via SIGKILL, they'd be able to do something like:
hostname:
processes:
- path: /bin/tor
args: -f torrc
- path: /bin/killall
start_time: 100
args: tor
Supporting this is an alternative to adding support in Shadow itself for soft/graceful shutdown (#1491).
Looking at an strace of a basic killall command:
$ strace -o strace.txt killall myprocessname
...
openat(AT_FDCWD, "/proc", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = 3
fstat(3, {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0
getdents64(3, /* 536 entries */, 32768) = 14136
getdents64(3, /* 0 entries */, 32768) = 0
close(3) = 0
openat(AT_FDCWD, "/proc/1/stat", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "1 (systemd) S 0 1 1 0 -1 4194560"..., 1024) = 199
close(3) = 0
openat(AT_FDCWD, "/proc/2/stat", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "2 (kthreadd) S 0 0 0 0 -1 212998"..., 1024) = 151
close(3)
...
It looks like we'd minimally need to emulate /proc/[pid]/stat.
This looks pretty straightforward:
$ cat /proc/295148/stat
295148 (sleep) S 287778 295148 287778 34817 295153 1077936128 83 0 0 0 0 0 0 0 20 0 1 0 44500553 8282112 129 18446744073709551615 94843815231488 94843815246881 140735516133392 0 0 0 0 0 0 1 0 0 17 11 0 0 0 0 0 94843815263152 94843815264384 94843834523648 140735516134804 140735516134815 140735516134815 140735516139497 0
There's a lot there, but we could probably get away with only implementing a few of these fields to start. See /proc/[pid]/stat in proc(5).
Supporting running the
killallcommand under Shadow would give users some flexibility on how processes are killed. e.g. if they wish a tor process to be gracefully shut down via SIGTERM near the end of the simulation instead of killed via SIGKILL, they'd be able to do something like:Supporting this is an alternative to adding support in Shadow itself for soft/graceful shutdown (#1491).
Looking at an strace of a basic killall command:
It looks like we'd minimally need to emulate
/proc/[pid]/stat.This looks pretty straightforward:
There's a lot there, but we could probably get away with only implementing a few of these fields to start. See
/proc/[pid]/statinproc(5).