Determine if only one instance is running: Difference between revisions
Content added Content deleted
(Added slightly hackish Python example.) |
m (Fixed formatting.) |
||
Line 13: | Line 13: | ||
import sys, os |
import sys, os |
||
def isOnlyInstance(): |
def isOnlyInstance(): |
||
frame = sys._getframe() |
frame = sys._getframe() |
Revision as of 04:35, 9 December 2007
Determine if only one instance is running
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
This task is to determine if there is only one instance of an application running.
Visual Basic
Language Version: 6
Dim onlyInstance as Boolean onlyInstance = not App.PrevInstance
Python
Language Version: 2.5
import sys, os def isOnlyInstance(): frame = sys._getframe() while frame.f_back: frame = frame.f_back if not os.system('(( $(ps -af | grep \'[' + frame.f_code.co_filename[0] + \ ']' + frame.f_code.co_filename[1:len(frame.f_code.co_filename)] + '\' | wc \ -l) > 1 ))'): return 0 else: return 1