Determine if only one instance is running: Difference between revisions

From Rosetta Code
Content added Content deleted
(New page: {{task}} This task is to determine if there is only one instance of an application running. =={{header|Visual Basic}}== '''Language Version:''' 6 Dim onlyInstance as Boolean onlyIns...)
 
(Added slightly hackish Python example.)
Line 8: Line 8:
Dim onlyInstance as Boolean
Dim onlyInstance as Boolean
onlyInstance = not App.PrevInstance
onlyInstance = not App.PrevInstance

=={{header|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

Revision as of 04:35, 9 December 2007

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