Question: I want to make a sh script that will only run at most once at any point. 

Say, if I exec the script then I go to exec the script again, how do I make it so that if the first exec of the script is still working the second one will fail with an error. I.e. I need to check if the script is running elsewhere before doing anything. How would I go about doing this??

The script I have runs a long running process (i.e. runs forever). I wanted to use something like cron to call the script every 15mins so in case the process fails, it will be restarted by the next cron run script.

Answer: 
Write the process id into a file and then when a new instance starts, check the file to see if the old instance is still running.
I suggest using `flock`, but in a different way than suggested by @Josef Kufner. I think this is quite easy and `flock` should be available on most systems by default:

```
flock -n lockfile myscript.sh

```