def scanProcessForMapping(pid, searchPortion, isExactMatch=False, ignoreCase=False):
try:   <EOL><INDENT>try:<EOL><INDENT>pid = int(pid)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>sys.stderr.write('<STR_LIT>' %(str(type(pid)),))<EOL>raise e<EOL><DEDENT>with open('<STR_LIT>' %(pid,), '<STR_LIT:r>') as f:<EOL><INDENT>contents = f.read()<EOL><DEDENT>lines = contents.split('<STR_LIT:\n>')<EOL>matchedMappings = []<EOL>if isExactMatch is True:<EOL><INDENT>if ignoreCase is False:<EOL><INDENT>isMatch = lambda searchFor, searchIn : bool(searchFor == searchIn)<EOL><DEDENT>else:<EOL><INDENT>isMatch = lambda searchFor, searchIn : bool(searchFor.lower() == searchIn.lower())<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if ignoreCase is False:<EOL><INDENT>isMatch = lambda searchFor, searchIn : bool(searchFor in searchIn)<EOL><DEDENT>else:<EOL><INDENT>isMatch = lambda searchFor, searchIn : bool(searchFor.lower() in searchIn.lower())<EOL><DEDENT><DEDENT>for line in lines:<EOL><INDENT>portion = '<STR_LIT:U+0020>'.join(line.split('<STR_LIT:U+0020>')[<NUM_LIT:5>:]).lstrip()<EOL>if isMatch(searchPortion, portion):<EOL><INDENT>matchedMappings.append('<STR_LIT:\t>' + line)<EOL><DEDENT><DEDENT>if len(matchedMappings) == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>cmdline = getProcessCommandLineStr(pid)<EOL>owner   = getProcessOwnerStr(pid)<EOL>return {<EOL>'<STR_LIT>' : searchPortion,<EOL>'<STR_LIT>'           : pid,<EOL>'<STR_LIT>'         : owner,<EOL>'<STR_LIT>'       : cmdline,<EOL>'<STR_LIT>' : matchedMappings,<EOL>}<EOL><DEDENT>except OSError:<EOL><INDENT>return None<EOL><DEDENT>except IOError:<EOL><INDENT>return None<EOL><DEDENT>except FileNotFoundError:<EOL><INDENT>return None<EOL><DEDENT>except PermissionError:<EOL><INDENT>return None<EOL><DEDENT>
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
        }