Это мой наивный подход, который не работать правильно:
Код: Выделить всё
#!/bin/bash
declare -i all_tests_res=0
declare -r PASSED=0
declare -r FAILED=1
# function to be run as background job
test_fn() {
slp_time=$(( RANDOM % 10 + 1 )) # tests have different duration
sleep "$slp_time" # long time running process imitations
if (( RANDOM % 2 == 0 )); then # even is success, odd is fail
kill -s USR1 "$PPID" # send signal to parent process by its PID
else
kill -s USR2 "$PPID" # send signal to parent process by its PID
fi
}
# function to set result of whole script to non null if there is one failed test
handler() {
local res=$1
if (( all_tests_res==0 && res==1 )); then
all_tests_res=1
fi
}
main() {
for (( i=0; i
Подробнее здесь: [url]https://stackoverflow.com/questions/79375497/is-there-a-way-to-send-signal-from-background-function-in-bash-to-parent-process[/url]
Мобильная версия