wait any process to exit

dm9pZCAq 59ad376e7c rename to `waitanypid` 1 month ago
include ea5295383b ignore hup signal 3 months ago
.gitignore 59ad376e7c rename to `waitanypid` 1 month ago
.gitmodules 49b1f92eb4 initial 5 months ago
LICENSE 49b1f92eb4 initial 5 months ago
Makefile 59ad376e7c rename to `waitanypid` 1 month ago
README.md 59ad376e7c rename to `waitanypid` 1 month ago
wait-parent.sh 59ad376e7c rename to `waitanypid` 1 month ago
waitanypid.asm 59ad376e7c rename to `waitanypid` 1 month ago

README.md

waitanypid

wait any process to exit

this is similar to the shell's builtin wait, but it can wait for any pid, not just the child pid

NOTE: waitanypid exits with 0 regardless of pid exit status

usage

waitanypid <pid> [cmd]
        pid     process id to wait for
        cmd     optionall command to run with '/bin/sh' after <pid> exits
# standard wait can only wait for child processes
sleep 10 & wait "${!}"

# waitanypid
waitanypid 1  # wait for init to stop :)

sh ./wait-parent.sh

see also wait-parent.sh

to see what actually happens in this script use htop -t and extrace -t (extrace)

for example it can be used in swallow script:

#!/bin/sh --
set -ue

id="$(xdo id)"
xdo hide "${id}"

ppid="${$}"
# shellcheck disable=2016
id="${id}" waitanypid "${ppid}" 'exec xdo show "${id:?}"' &

exec "${@}"

run-time dependencies

how to build

build-time dependencies:

make FASMG=./path/to/fasmg-executable

this will create a static waitanypid executable of 1469 bytes in size and without any run-time dependencies other than the Linux kernel