i'm running a script that calls a child script that in turn calls other child scripts and processes.
some of the child processes use a lot of disk io and cpu, and overheats the cpu, causing a crash or errors. i guess i can thank intel for that. this isn't a request for information to fix my cpu.
i want to pause the script for 2mins every 5mins, to allow the cpu to cool down.
this is in my parent script:
for dir in * ; do
if [ -d "$d" ]; then
printf "$dir."
./subscript.sh "${dir}" &
echo "$!" > ./"${dir}.pid" &
./pauser.sh "${dir}"
#rm ./"{d}.pid"
touch "{d}.pid.ended"
fi
done
and this is my pauser.sh script:
#!/bin/bash
pauser() {
printf "@" &&
sleep "${2}m" &&
check_running "${1}" &&
kill -STOP "$(cat ${1}.pid)" &&
sleep "${3}m" &&
printf "." &&
check_running "${1}" &&
kill -CONT "$(cat ${1}.pid)"
}
check_running() {
if [ -f "${1}.pid.ended" ]; then
rm "${1}.pid.ended"
exit 0
fi
}
while true
do
if [ -f "${1}.pid.ended" ]; then
rm "${1}.pid.ended"
exit 0
else
pauser "${1}" "5" "2"
fi
done
this pauser script doesn't pause the child of child processes, i think because the child of child scripts/processes have different pid's.
i've read that child of child processes can be grouped, if so, how do i pause and resume the entire group of child processes from the parent script?
set +m
to spawn each successive child process in it's own group, then by usingkill -STOP "-${pid}
the negative before$pid
allows to pause the entire group, but not the parent script – laughing muppet Sep 09 '21 at 13:27