ProcessMappingScanner (version 2.3.1)
index

# Copyright (c) 2015, 2016, 2017 Tim Savannah under terms of the Lesser General GNU Public License Version 3 ( LGPLv3 )
# You should have received a copy of the license as LICENSE with this distribution. It contains the full license
#
# This module contains methods designed to work under UNIX to determine various information associated with processes.
# The include shared mappings (like shared lib, running executable, etc), process owner, process commandline, and open files, devices, or fds.

 
Package Contents
       

 
Functions
       
getAllRunningPids()
getAllRunningPids - Gets list of all pids that are running on a given system
 
@return <list<int>> - A list of pids (process IDs).
getProcessCommandLineList(pid)
getProcessCommandLineList - Gets the commandline (program + argumentS) of a given pid as a list.
 
@param pid <int> - Process ID
 
@return - None if process not found or can't be determined. Otherwise a list representing argv. First argument is process name, remainder are arguments.
 
@note - Use this if you care about whether a process had a space in the commands
getProcessCommandLineStr(pid)
getProcessCommandLineStr - Gets a the commandline (program + arguments) of a given pid
 
@param pid <int> - Process ID
 
@return - None if process not found or can't be determined. Otherwise a string of commandline.
 
@note Caution, args may have spaces in them, and you cannot surmise from this method. If you care (like trying to replay a command), use getProcessCommandLineList instead
getProcessCwd(pid)
getProcessCwd - Gets the cwd (current working directory) of a given pid
 
@param pid <int> - Process ID
 
@return <str/None> - None if process not found or can't be determined. Otherwise, a string of the CWD
getProcessOwner(pid)
getProcessOwner - Get the process owner of a pid
 
@param pid <int> - process id
 
@return - None if process not found or can't be determined. Otherwise, a dict: 
    {
        uid  - Owner UID
        name - Owner name, or None if one cannot be determined
    }
getProcessOwnerStr(pid)
getProcessOwner - Get Process owner of a pid as a string instead of components (#getProcessOwner)
 
@return - Returns username if it can be determined, otherwise uid, otherwise "unknown"
scanAllProcessesForMapping(searchPortion, isExactMatch=False, ignoreCase=False)
scanAllProcessesForMapping - Scans all processes on the system for a given search pattern.
 
    @param searchPortion <str> - A mapping for which to search, example: libc or python or libz.so.1. Give empty string to return all mappings.
    @param isExactMatch <bool> Default False - If match should be exact, otherwise a partial match is performed.
    @param ignoreCase <bool> Default False - If True, search will be performed case-insensitively
 
@return - <dict> - A dictionary of pid -> mappingResults for each pid that matched the search pattern. For format of "mappingResults", @see scanProcessForMapping
scanAllProcessesForOpenFile(searchPortion, isExactMatch=True, ignoreCase=False)
scanAllProcessessForOpenFile - Scans all processes on the system for a given filename
 
    @param searchPortion <str> - Filename to check
    @param isExactMatch <bool> Default True - If match should be exact, otherwise a partial match is performed.
    @param ignoreCase <bool> Default False - If True, search will be performed case-insensitively
 
@return - <dict> - A dictionary of pid -> mappingResults for each pid that matched the search pattern. For format of "mappingResults", @see scanProcessForOpenFile
scanProcessForMapping(pid, searchPortion, isExactMatch=False, ignoreCase=False)
scanProcessForMapping - Searches a given pid's mappings for a certain pattern.
 
    @param pid <int> - A running process ID on this system
    @param searchPortion <str> - A mapping for which to search, example: libc or python or libz.so.1. Give empty string to return all mappings.
    @param isExactMatch <bool> Default False - If match should be exact, otherwise a partial match is performed.
    @param ignoreCase <bool> Default False - If True, search will be performed case-insensitively
 
    @return <dict> - If result is found, the following dict is returned. If no match found on the given pid, or pid is not found running, None is returned.
        {
            'searchPortion' : The passed search pattern
            'pid'           : The passed pid (as an integer)
            'owner'         : String of process owner, or uid if no mapping can be found, or "unknown" if neither could be determined.
            'cmdline'       : Commandline string
            'matchedMappings' : All mappings likes that matched the given search pattern
        }
scanProcessForOpenFile(pid, searchPortion, isExactMatch=True, ignoreCase=False)
scanProcessForOpenFile - Scans open FDs for a given pid to see if any are the provided searchPortion
 
    @param searchPortion <str> - Filename to check
    @param isExactMatch <bool> Default True - If match should be exact, otherwise a partial match is performed.
    @param ignoreCase <bool> Default False - If True, search will be performed case-insensitively
 
@return -  If result is found, the following dict is returned. If no match found on the given pid, or the pid is not found running, None is returned.
        {
            'searchPortion' : The search portion provided
            'pid'           : The passed pid (as an integer)
            'owner'         : String of process owner, or "unknown" if one could not be determined
            'cmdline'       : Commandline string
            'fds'           : List of file descriptors assigned to this file (could be mapped several times)
            'filenames'     : List of the filenames matched
        }

 
Data
        __all__ = ('getProcessOwner', 'getProcessOwnerStr', 'getProcessCommandLineStr', 'getProcessCommandLineList', 'getProcessCwd', 'getAllRunningPids', 'scanProcessForMapping', 'scanAllProcessesForMapping', 'scanProcessForOpenFile', 'scanAllProcessesForOpenFile')
__version_tuple__ = (2, 3, 1)