aboutsummaryrefslogtreecommitdiff
path: root/libbutl/utility.bash.in
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-08-10 20:47:11 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-08-12 11:55:44 +0300
commit46c7d448f27e8fc213c50cd241914b2d94e2e308 (patch)
tree5a1ec4f333afb4eea02ff9f48c9464288d099ebb /libbutl/utility.bash.in
parent7c37a912d9e8836a49c25445d53d7f4e5005122e (diff)
Fix bash coprocess usage races
Diffstat (limited to 'libbutl/utility.bash.in')
-rw-r--r--libbutl/utility.bash.in25
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
+}