Last active
June 15, 2022 17:24
-
-
Save azat/affbda3f8c6b5c38648d4ab105777d88 to your computer and use it in GitHub Desktop.
bash bug: wait_for: No record of process (had been fixed in bash 5.1+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Reproducer for bash bug that had been fixed in bash 5.1+ [1], report [2] | |
# | |
# [1]: https://git.savannah.gnu.org/cgit/bash.git/commit/?h=bash-5.1&id=8868edaf2250e09c4e9a1c75ffe3274f28f38581 | |
# [2]: https://lists.gnu.org/archive/html/bug-bash/2019-05/msg00110.html | |
# | |
function thread_worker() | |
{ | |
set -e | |
# echo "thread_worker_pid=$BASHPID (started)" | |
trap "STOP_THE_LOOP=1; sleep 0.5" INT | |
STOP_THE_LOOP=0 | |
while [[ $STOP_THE_LOOP != 1 ]]; do | |
sleep 0.1 | grep foo || : | |
done | |
# echo "thread_worker_pid=$BASHPID (finished)" | |
} | |
function main() | |
{ | |
echo "main_pid=$BASHPID" | |
local pids=() | |
for i in $(seq 0 100); do | |
thread_worker & | |
pids+=( $! ) | |
done | |
sleep 0.1 | |
echo "Sending INT" | |
wait & | |
sleep 0.1 | |
kill -INT "${pids[@]}" | |
sleep 0.1 | |
wait | |
} | |
main "$@" |
Author
azat
commented
Jun 15, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment