Determine if only one instance is running

From Rosetta Code
Revision as of 04:35, 9 December 2007 by rosettacode>Tclamb (Added slightly hackish Python example.)
Task
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.

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