Let's start our activity as follows:
- Open a new terminal and create a new script by the name of mylock.sh with the following contents:
#!/bin.bashLOCKFILE="/tmp/mylock"function setup() { # $$ will provide the process ID TMPFILE="${LOCKFILE}.$$" echo "$$" > "${TMPFILE}" # Now we use hard links for atomic file operations if ln "${TMPFILE}" "${LOCKFILE}" 2>&- ; then echo "Created tmp lock" else echo "Locked by" $(<$LOCKFILE) rm "${TMPFILE}" exit 1 fi trap "rm ${TMPFILE} ${LOCKFILE}" SIGINT SIGTERM SIGKILL}setupecho "Door was left unlocked"exit 0
- Execute the script with the $ bash mylock.sh script and review the console's output.
- Next, we know that the script is looking for a particular lock file. What happens when we create ...