diff options
Diffstat (limited to 'libbutl/utility.bash.in')
-rw-r--r-- | libbutl/utility.bash.in | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/libbutl/utility.bash.in b/libbutl/utility.bash.in index 56bd3ab..5f51a2c 100644 --- a/libbutl/utility.bash.in +++ b/libbutl/utility.bash.in @@ -23,3 +23,28 @@ function butl_path () # dirname "${BASH_SOURCE[0]}" } + +# Resume a stopped process execution by sending it the SIGCONT signal. +# +# Note that to avoid races the function waits until the process enters the +# stopped state. +# +function butl_resume_process () # <pid> +{ + local pid="$1" + + while true; do + + # Note that while the ps's -o option 'state' value is not specified by + # POSIX, it is supported by all the major implementations with the leading + # 'T' character indicating the 'stopped' process run state. + # + local s + s="$(ps -p "$pid" -o state=)" + + if [ "${s:0:1}" == "T" ]; then + kill -SIGCONT "$pid" + break + fi + done +} |