diff --git a/framework/subsystems/ogsmd/helpers.py b/framework/subsystems/ogsmd/helpers.py
index 31a3e68..b89f332 100644
|
a
|
b
|
class BiDict( object ): |
| 110 | 110 | return self._d.keys() + self._back.keys() |
| 111 | 111 | |
| 112 | 112 | #=========================================================================# |
| 113 | | def processIterator(): |
| | 113 | def processIterator(nameToFind): |
| | 114 | #=========================================================================# |
| | 115 | for entry in os.listdir( "/proc" ): |
| | 116 | fileName = os.path.join("/proc", entry, "cmdline") |
| | 117 | if os.access(fileName, os.R_OK): |
| | 118 | cmdline=file(fileName).read() |
| | 119 | executablePath = cmdline.split("\x00")[0] |
| | 120 | executableName = executablePath.split(os.path.sep)[-1] |
| | 121 | #entry = pid, cmdline = cmdline file contents |
| | 122 | yield (entry, cmdline, executablePath, executableName) |
| | 123 | |
| 114 | 124 | #=========================================================================# |
| 115 | | for entry in os.listdir( "/proc" ): |
| 116 | | try: |
| 117 | | pid = int( entry ) |
| 118 | | except ValueError: |
| 119 | | continue |
| 120 | | else: |
| 121 | | name = open( "/proc/%s/cmdline" % pid ).read().split( '\0' )[0] |
| 122 | | yield name, pid |
| | 125 | def processFinder(nameToFind, matchType): |
| | 126 | #=========================================================================# |
| | 127 | for (entry, cmdline, executablePath, executableName) in processIterator(nameToFind): |
| | 128 | if matchType=="posix": |
| | 129 | if executableName == nameToFind: |
| | 130 | yield entry |
| | 131 | elif matchType=="weak": |
| | 132 | if executablePath.find(nameToFind) != -1: |
| | 133 | yield entry |
| | 134 | elif matchType=="reallyweak": |
| | 135 | if cmdline.find(nameToFind) != -1: |
| | 136 | yield entry |
| 123 | 137 | |
| 124 | 138 | #=========================================================================# |
| 125 | | def killall( nameToKill ): |
| | 139 | def killall( nameToKill, matchType="posix", killSignal=signal.SIGTERM): |
| 126 | 140 | #=========================================================================# |
| 127 | | [ os.kill( pid, signal.SIGTERM ) for name, pid in processIterator() if name == nameToKill ] |
| | 141 | killedPids=[] |
| | 142 | for pid in processFinder(nameToKill, matchType): |
| | 143 | try: |
| | 144 | os.kill(int(pid), killSignal) |
| | 145 | killedPids.append(int(pid)) |
| | 146 | except OSError: #permission denied/bad signal/etc... |
| | 147 | pass |
| | 148 | return killedPids |
| 128 | 149 | |
| 129 | 150 | #=========================================================================# |
| 130 | 151 | if __name__ == "__main__": |