<div dir="ltr">I do not know if it works for you but to manage processes inside docker I use supervisord<br><br><a href="http://supervisord.org/">http://supervisord.org/</a><br> <br>you can run the bash script with supervisor once the process running then you can pass the files to FIFO_FILE<br>when you don't need the script only stop supervisors and that will stop the process...</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jul 28, 2024 at 12:22 PM John Steel via kwlug-disc <<a href="mailto:kwlug-disc@kwlug.org">kwlug-disc@kwlug.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I’m having trouble figuring out how to manage a subprocess… I’m probably overcomplicating this… <br>
<br>
I’ve made a script called checksum.sh. I want it to keep moving data from a fifo to sha256sum until it’s terminated. But it seems when I kill it the cat and sha256sum are gone before my finalize method is called? If I can kill cat and let that sub shell exit gracefully I think I should see the sha256sum come out on stderr. <br>
<br>
#!/bin/bash<br>
# This is checksum.sh<br>
<br>
FIFO_FILE="${FIFO_FILE:-sha256sum_fifo}"<br>
CAT_PID_FILE="$(mktemp -p /dev/shm $$_cat_pid.XXXXXX)"<br>
export CAT_PID_FILE FIFO_FILE<br>
mkfifo "$FIFO_FILE"<br>
<br>
finalize() {<br>
pgrep -fl "cat fifo $FIFO_FILE" > /dev/stderr<br>
pgrep -fl sha256sum > /dev/stderr<br>
<br>
cat_pid="$(cat "$CAT_PID_FILE")"<br>
rm "$CAT_PID_FILE"<br>
kill -s SIGTERM "$cat_pid" && wait "$cat_pid"<br>
exit 0<br>
}<br>
<br>
trap finalize SIGTERM<br>
trap finalize SIGHUP <br>
trap finalize SIGINT <br>
trap finalize SIGQUIT <br>
<br>
# Start the cat process and capture its PID<br>
while [ -f "$CAT_PID_FILE" ]; do <br>
cat "$FIFO_FILE" & cat_pid=$!<br>
echo "$cat_pid" > "$CAT_PID_FILE"<br>
wait "$cat_pid"<br>
sleep 0.01<br>
done | sha256sum > /dev/stderr<br>
<br>
Here’s how I’m running it: <br>
<br>
docker run -it -v $PWD:/app alpine sh -xc '<br>
apk add bash procps<br>
export FIFO_FILE="$(mktemp -u -p /dev/shm fifo_$$.XXXXXX)"<br>
bash -x /app/checksum.sh &<br>
sleep 0.2<br>
jobs<br>
ps -ef --forest<br>
echo "First data to hash" > $FIFO_FILE<br>
sleep 0.2<br>
ps -ef --forest<br>
echo "More data to hash" > $FIFO_FILE<br>
kill %1<br>
sleep 1<br>
‘<br>
<br>
Am I missing something obvious? If it’s possible without the loop that’d be great too but I found that if I connect sha256sum directly to the fifo it exits after the first write to the fifo.<br>
<br>
Should I learn how to use socat for this? From a few of the things I’ve read it sounds like it could make this simpler? _______________________________________________<br>
kwlug-disc mailing list<br>
To unsubscribe, send an email to <a href="mailto:kwlug-disc-leave@kwlug.org" target="_blank">kwlug-disc-leave@kwlug.org</a><br>
with the subject "unsubscribe", or email<br>
<a href="mailto:kwlug-disc-owner@kwlug.org" target="_blank">kwlug-disc-owner@kwlug.org</a> to contact a human being.<br>
</blockquote></div>