Parse the output of `ps aux` into a list of dictionaries representing the parsed process information from each row of the output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
|# -*- coding: utf-8 -*-|
|Parse the output of `ps aux` into a list of dictionaries representing the parsed|
|process information from each row of the output. Keys are mapped to column names,|
|parsed from the first line of the process' output.|
|:returns: List of dictionaries, each representing a parsed row from the command output|
|output = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE).stdout.readlines()|
|headers = [h for h in ' '.join(output.strip().split()).split() if h]|
|raw_data = map(lambda s: s.strip().split(None, len(headers) - 1), output[1:])|
|return [dict(zip(headers, r)) for r in raw_data]|
May 20, 2018
Jun 12, 2018
cool, saved me from trying to get psutil to compile on an unsupported old os..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment