Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • I thought of using lock but i want to do this without creating any temporary files. Already i am using some temp files for the script. Commented Dec 25, 2013 at 6:51
  • It's insecure (anyone could run a process with a matching name), but you can avoid tempfiles with if pgrep $(basename $0) 2> /dev/null; then echo "Already running"; exit 1; fi Commented Dec 25, 2013 at 7:25
  • 1
    Thanks for the answer, after trying different ways, i finally chose the locking mechanism. I am applying a lock when a script is executed with some arguments and have given the name of the lock file <arg1_arg2> which i am deleting at the end of the script. This way i am able to have multiple instances of the script running with different arguments than the one already running and block multiple instances of the script with the same arguments so that the script is not executed twice with the arguments already being used in running instace which was my actual requirement. Commented Dec 28, 2013 at 12:46