Check if shell script is already running

Mir Adnan
1 min readMay 7, 2020

One of my shell script was overlapping which resulted in 100% memory usage. So, I have written a validation that checks if the same shell script is running or not. If it’s not running it will continue to process further, otherwise exit. Below is the code snippet.

#!/bin/sh[ "$(pidof -x $(basename $0))" != $$ ] && exit## process further

--

--