Author: dmeyer
Date: Sat Jan 13 20:38:41 2007
New Revision: 2387

Modified:
   trunk/base/src/utils.py

Log:
create function to track if a kaa app is running

Modified: trunk/base/src/utils.py
==============================================================================
--- trunk/base/src/utils.py     (original)
+++ trunk/base/src/utils.py     Sat Jan 13 20:38:41 2007
@@ -154,3 +154,32 @@
     os.dup2(stderr.fileno(), sys.stderr.fileno())
 
     return lock
+
+
+def is_running(name):
+    """
+    Check if the program with the given name is running. The program
+    must have called set_running itself. Returns the pid or 0.
+    """
+    if not os.path.isfile(kaa.tempfile('run/' + name)):
+        return 0
+    run = open(kaa.tempfile('run/' + name))
+    pid = run.readline().strip()
+    cmdline = run.readline()
+    run.close()
+    if not os.path.exists('/proc/%s/cmdline' % pid):
+        return 0
+    if open('/proc/%s/cmdline' % pid).readline() == cmdline:
+        return int(pid)
+    return 0
+
+
+def set_running(name):
+    """
+    Set this program as running with the given name.
+    """
+    cmdline = open('/proc/%s/cmdline' % os.getpid()).readline()
+    run = open(kaa.tempfile('run/' + name), 'w')
+    run.write(str(os.getpid()) + '\n')
+    run.write(cmdline)
+    run.close()

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to