title: bash locking mechanism using sockets
body: <p>I have found this solution to do a process locking mechanism in python:</p>
  
  <pre><code>import socket
  import sys
  import time
  
  def get_lock(process_name):
      global lock_socket
      lock_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
      try:
          lock_socket.bind('\0' + process_name)
          print 'I got the lock'
      except socket.error:
          print 'lock exists'
          sys.exit()
  
  get_lock('running_test')
  while True:
      time.sleep(3)
  </code></pre>
  
  <p>this was found here: 
  <a href="https://stackoverflow.com/questions/788411/check-to-see-if-python-script-is-running">Check to see if python script is running</a></p>
  
  <p>Can the same be achieved in bash? If so, could someone please post a working example?</p>
  
  <p>Many thanks</p>