Created
January 13, 2010 10:22
-
-
Save abbot/276090 to your computer and use it in GitHub Desktop.
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
# -*- encoding: utf-8 -*- | |
import sys | |
__all__ = ['proc_stat'] | |
_pstat_parts = [ | |
('pid', int), | |
('comm', str), | |
('state', str), | |
('ppid', int), | |
('pgrp', int), | |
('session', int), | |
('tty_nr', int), | |
('tpgid', int), | |
('flags', int), | |
('minflt', int), | |
('cminflt', int), | |
('majflt', int), | |
('cmajflt', int), | |
('utime', int), | |
('stime', int), | |
('cutime', int), | |
('cstime', int), | |
('priority', int), | |
('nice', int), | |
('num_threads', int), | |
('itrealvalue', int), | |
('starttime', int), | |
('vsize', int), | |
('rss', int), | |
('rsslim', int), | |
('startcode', int), | |
('endcode', int), | |
('startstack', int), | |
('kstkesp', int), | |
('kstkeip', int), | |
('signal', int), | |
('blocked', int), | |
('sigignore', int), | |
('sigcatch', int), | |
('wchan', int), | |
('nswap', int), | |
('cnswap', int), | |
('exit_signal', int), | |
('processor', int), | |
('rt_priority', int), | |
('policy', int), | |
('delayacct_blkio_ticks', int), | |
('guest_time', int), | |
('cguest_time', int), | |
] | |
if sys.platform == 'linux2': | |
def proc_stat(pid=None): | |
if pid is not None: | |
path='/proc/%d/stat' % pid | |
else: | |
path='/proc/self/stat' | |
line = open(path, 'r').read() | |
line.strip() | |
res = {} | |
for i, elt in enumerate(line.split()): | |
part = _pstat_parts[i] | |
res[part[0]] = part[1](elt) | |
return res | |
else: | |
def proc_stat(pid=None): | |
raise NotImplementedError("No implementation for this platform.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment