Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fcntl
- pid_file = 'program.pid'
- fp = open(pid_file, 'w')
- try:
- fcntl.lockf(fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
- except IOError:
- # another instance is running
- sys.exit(0)
- name = "MyApp-%s" % wx.GetUserId()
- checker = wx.SingleInstanceChecker(name)
- if checker.IsAnotherRunning():
- return False
- linux# pidof myapp
- 8947
- linux# pidof nonexistent_app
- linux#
- import os
- os.getpid()
- cmd = "ps -p %s -o comm=" % var_run_pid
- app_name = os.popen(cmd).read().strip()
- if len(app_name) > 0:
- Already running
Add Comment
Please, Sign In to add comment