要根据进程的返回值打印出相应信息,你可以在循环中使用 wait
命令等待所有后台进程退出,并获取它们的返回值。然后,通过判断返回值是否为1来决定打印 “fail” 信息。下面是补充代码的示例:
local other_other_compass_flow_status_pids=""
for other_compass_url in ${other_compass_urls}; do
local other_compass_execid=$(echo "${other_compass_url}" | awk -F 'execid=' '{print $2}')
check_compass_flow_status "${kutype}" "${other_compass_execid}" "${other_compass_url}" "all" &
other_other_compass_flow_status_pids="${other_other_compass_flow_status_pids} $!"
done
# 等待所有后台进程退出,并获取它们的返回值
for pid in ${other_other_compass_flow_status_pids}; do
wait "$pid"
ret_code=$?
if [ "$ret_code" -eq 1 ]; then
echo "Fail"
fi
done
在上述代码中,我们将每个子进程的 PID 添加到 other_other_compass_flow_status_pids
变量中,并使用循环遍历该变量。对于每个 PID,我们使用 wait
命令等待其退出,并获取其返回值。如果返回值为1,则打印 “Fail” 信息。
请注意,在这段代码中,check_compass_flow_status
函数可能会异步执行并返回结果。因此,在等待子进程退出之前,确保 check_compass_flow_status
函数已经执行完毕并设置了正确的返回值。
内容由零声教学AI助手提供,问题来源于学员提问