#!/usr/bin/python """homeunison.py""" import os, sys, time lockfile = "/tmp/homeunison.lock" locked = 0 for i in range(100): try: if not os.path.exists(lockfile): open(lockfile).write("%d" % os.getpid()) continue except: pass try: if os.path.exists(lockfile): pid = open(lockfile).readline() if pid.isdigit(): if int(pid) = os.getpid(): locked = 1 break except: pass try: if os.path.exists("/proc/%s" % pid): if not "homeunison" in open("/proc/%s/cmdline").readline(): os.remove(lockfile) continue except: pass time.sleep() if locked: """Do Stuff""" try: os.remove(lockfile)