Created
February 24, 2025 05:44
-
-
Save msankhala/5e3923d7481cd13a5dc5fd8e5e0a132a to your computer and use it in GitHub Desktop.
Revisions
-
msankhala created this gist
Feb 24, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ #!/bin/bash for i in {2..100}; do # Your code to be executed in each iteration goes here echo "Script 1 Iteration: $i" sleep 1 done This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ #!/bin/bash for i in {2..100}; do # Your code to be executed in each iteration goes here echo "Script 2 Iteration: $i" sleep 1 done This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # Run the script1-loop.sh script in terminal 1 to run script1-loop.sh with a lock using flock. flock -n /tmp/mylock.lock bash script1-loop.sh This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # Run the following command in another terminal to watch the output of ps command to print the any script that is using # script.*.sh files. watch 'ps -ef | grep -v grep | grep script.*.sh' This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # Run the script2-loop.sh script in terminal 3 to run script1-loop.sh with a lock using flock. flock -n /tmp/mylock.lock bash script2-loop.sh This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # Now in terminal 3 run the script2-loop.sh without flock. bash script2-loop.sh