[tuxdroid-svn] r5114 - software_suite_v3/smart-core/smart-server/trunk/util/smartcore
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-07-15 11:16:45
|
Author: remi Date: 2009-07-15 13:16:31 +0200 (Wed, 15 Jul 2009) New Revision: 5114 Modified: software_suite_v3/smart-core/smart-server/trunk/util/smartcore/OldProcessKiller.py Log: * Added a function to retrieve a list of process id/name/cmdline on linux Modified: software_suite_v3/smart-core/smart-server/trunk/util/smartcore/OldProcessKiller.py =================================================================== --- software_suite_v3/smart-core/smart-server/trunk/util/smartcore/OldProcessKiller.py 2009-07-14 17:53:58 UTC (rev 5113) +++ software_suite_v3/smart-core/smart-server/trunk/util/smartcore/OldProcessKiller.py 2009-07-15 11:16:31 UTC (rev 5114) @@ -4,8 +4,58 @@ # http://www.gnu.org/copyleft/gpl.html import os +import sys # ------------------------------------------------------------------------------ +# Create a process list as pid, name, command line. Unix. +# ------------------------------------------------------------------------------ +def __getProcessIdNameCmdLineListUnix(): + """Create a process list as pid, name, command line. Unix. + """ + def getPidList(): + pidList = [] + for pidDir in os.listdir("/proc/"): + try: + pid = int(pidDir) + except: + continue + pidList.append(pid) + return pidList + + def getProcessCmdLine(pid): + fileName = "/proc/%d/cmdline" % pid + if not os.path.isfile(fileName): + return "" + else: + try: + f = open(fileName, "r") + result = f.read().replace("\x00", " ") + f.close() + except: + return "" + return result + + def getProcessName(pid): + fileName = "/proc/%d/status" % pid + if not os.path.isfile(fileName): + return "" + else: + try: + f = open(fileName, "r") + result = f.readline()[6:-1] + f.close() + except: + return "" + return result + + result = [] + pidList = getPidList() + for pid in pidList: + e = [pid, getProcessName(pid), getProcessCmdLine(pid)] + result.append(e) + return result + +# ------------------------------------------------------------------------------ # Kill all process alive from a previous instance of smart-core. Window. # ------------------------------------------------------------------------------ def __killOldSmartCoreChildrenWin32(): @@ -38,7 +88,7 @@ win32api.CloseHandle(handle) except: pass - + # ------------------------------------------------------------------------------ # Kill previous smart-server. Window. # ------------------------------------------------------------------------------ @@ -73,7 +123,7 @@ """Kill all process alive from a previous instance of smart-core. Unix. """ pass - + # ------------------------------------------------------------------------------ # Kill previous smart-server. Unix. # ------------------------------------------------------------------------------ @@ -92,7 +142,7 @@ __killOldSmartCoreChildrenWin32() else: __killOldSmartCoreChildrenUnix() - + # ------------------------------------------------------------------------------ # Kill previous smart-server. # ------------------------------------------------------------------------------ |