test: avoid subprocesses when reading fixture process identities

This commit is contained in:
m4air
2026-09-28 07:37:06 -07:00
parent fa5ccd84f8
commit 8d516cc28e
2 changed files with 8 additions and 4 deletions
@@ -48,9 +48,12 @@ read_start_ticks() {
local pid=$1
[[ -r "/proc/$pid/stat" ]] || return 1
local stat
stat=$(cat "/proc/$pid/stat") || return 1
local -a fields
stat=$(<"/proc/$pid/stat") || return 1
# comm is parenthesized and may contain spaces or parentheses.
awk '{print $20}' <<< "${stat##*) }"
read -r -a fields <<< "${stat##*) }"
((${#fields[@]} >= 20)) || return 1
printf '%s\n' "${fields[19]}"
}
identity_alive() {
@@ -208,8 +211,8 @@ report_launcher_exit() {
cleanup() {
local status=$?
trap - EXIT
collect_state_processes TERM
signal_process_group TERM || true
collect_state_processes TERM
signal_owned_processes TERM || true
if ! wait_for_owned_exit 10 TERM; then
signal_process_group KILL || true
@@ -12,7 +12,8 @@ const functions = oracle.slice(oracle.indexOf('read_start_ticks()'), oracle.inde
function isRunning(pid) {
try {
return readFileSync(`/proc/${pid}/stat`, 'utf8').split(') ')[1][0] !== 'Z'
const stat = readFileSync(`/proc/${pid}/stat`, 'utf8')
return stat.slice(stat.lastIndexOf(') ') + 2)[0] !== 'Z'
} catch {
return false
}