Skip to content

Instantly share code, notes, and snippets.

@abbot
Created January 13, 2010 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abbot/276090 to your computer and use it in GitHub Desktop.
Save abbot/276090 to your computer and use it in GitHub Desktop.
# -*- 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