process defer - execute a command after a specified process (by PID) exits

dm9pZCAq 052c6393d3 rename to `pd` 5 bulan lalu
include ea5295383b ignore hup signal 10 bulan lalu
.gitignore 052c6393d3 rename to `pd` 5 bulan lalu
.gitmodules 6cfa5aeabd .gitmodules: change notabug to codeberg 5 bulan lalu
LICENSE 49b1f92eb4 initial 1 tahun lalu
Makefile 052c6393d3 rename to `pd` 5 bulan lalu
README.md 052c6393d3 rename to `pd` 5 bulan lalu
pd.asm 052c6393d3 rename to `pd` 5 bulan lalu
wait-parent.sh 052c6393d3 rename to `pd` 5 bulan lalu

README.md

pd

process defer - execute a command after a specified process (by PID) exits

this is similar to the shell's builtin wait, but it can wait for any pid, not just the child pid (also it is similar to waitpid(1) from util-linux, but pd was created before waitpid existed)

NOTE: if no cmd is provided, pd always exits with 0 regardless of the PID exit status, but if a cmd is provided, pd will exit with the exit code of that cmd

usage

pd <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 "${!}"

# pd
pd 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}" pd "${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 pd executable of 1469 bytes in size and without any run-time dependencies other than the Linux kernel