A mutex is a mutual exclusive lock. Your procN.sh scripts never test whether the mutex is held by another process before "locking".
If you let core.sh start the other scripts, it would be easy for it to wait for the completion of them:
#!/bin/sh
./proc1.sh &
./proc2.sh &
./proc3.sh &
wait
# other processing
This removes the need for the lock files altogether. If that's not possible, consider
#!/bin/sh
while [ -e "$HOME/locks/proc1.signature.mutex" ] ||
[ -e "$HOME/locks/proc2.signature.mutex" ] ||
[ -e "$HOME/locks/proc3.signature.mutex" ]
then
echo 'waiting...'
sleep 10
done
# other processing
To avoid leaving files behind by the procN.sh scripts if they die of unnatural causes, use a trap:
#!/bin/sh
lockfile="$HOME/locks/proc1.signature.mutex"
while [ -e "$lockfile" ]; do
echo 'Can not get lock. Waiting...' >&2
sleep 10
done
## alternatively:
# [ -e "$lockfile" ] && { echo 'something is wrong' >&2; exit 1; }
trap 'rm "$lockfile"; exit' EXIT INT TERM HUP
touch "$lockfile"
# etc.
# no need to rm the lock file at the end
Note that there is a space between the -e "$lockfile" test and the touch in which another process may lock the same file.
To avoid this, use a lock directory instead:
#!/bin/sh
lockdir="$HOME/locks/proc1.signature.mutex"
while ! mkdir "$lockdir"; do
echo 'Can not get lock. Waiting...' >&2
sleep 10
done
trap 'rmdir "$lockdir"; exit' EXIT INT TERM HUP
# etc.
# no need to rmdir the lock dir at the end
You may also use a symbolic link in a similar way.
Note that I've used a path under $HOME for the lock files/directories. If using /tmp, any user could potentially lock your script out of action by simply creating the correct file/directory.
trapso that the file.mutexis deleted on exit i.e:trap 'rm -f /tmp/proc3.signature.mutex' EXIT.core.shstart the other scripts as background jobs, then usewaitto wait for them to finish. No need for lock files (these aren't mutexes).