/usr/lib/python2.7/dist-packages/framework/patterns/utilities.py is in fso-frameworkd 0.9.5.9+git20110512-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #!/usr/bin/env python
"""
freesmartphone.org Framework Daemon
(C) 2009 Michael 'Mickey' Lauer <mlauer@vanille-media.de>
GPLv2 or later
Package: framework.patterns
Module: utilities
"""
import os, signal
import logging
logger = logging.getLogger( "mppl.utilities" )
#=========================================================================#
def processIterator():
#=========================================================================#
for entry in os.listdir( "/proc" ):
fileName = os.path.join( "/proc", entry, "cmdline" )
if os.access( fileName, os.R_OK ):
cmdline = file( fileName ).read()
executablePath = cmdline.split("\x00")[0]
executableName = executablePath.split(os.path.sep)[-1]
#entry = pid, cmdline = cmdline file contents
yield (entry, cmdline, executablePath, executableName)
#=========================================================================#
def processFinder(nameToFind, matchType):
#=========================================================================#
for entry, cmdline, executablePath, executableName in processIterator():
if matchType == "posix":
if executableName == nameToFind:
yield int( entry )
elif matchType == "weak":
if executablePath.find( nameToFind ) != -1:
yield int( entry )
elif matchType == "reallyweak":
if cmdline.find( nameToFind ) != -1:
yield int( entry )
#=========================================================================#
def killall( nameToKill, matchType="posix", killSignal=signal.SIGTERM ):
#=========================================================================#
killedPids = []
for pid in processFinder( nameToKill, matchType ):
try:
os.kill( pid, killSignal )
except OSError, IOError: # permission denied/bad signal/process vanished/etc...
pass
else:
killedPids.append( pid )
return killedPids
|