pyprocps
pyprocpsは/procにPythonらしくアクセスできるモジュールです。
使い方は以下のページに簡潔に記載されています。
http://eli.criffield.net/pyprocps/
で、2.6.18以降だと、エラーになります。
プロセスの情報に「(clock tick (100分の1秒) 単位での) ブロック I/O の総遅延量(delayacct_blkio_ticks)」が追加されており、その情報にpyprocps側が対応できていないようです。
以下がパッチです。
--- pyprocps_org.py 2007-04-19 11:12:20.000000000 +0900 +++ pyprocps.py 2007-04-19 11:52:17.000000000 +0900 @@ -121,7 +121,9 @@ "exit_signal",# 37 Signal to be sent to parent when we die. "processor", # 38 CPU number last executed on "rt_priority",# 39 Real-time scheduling priority, NULL if kernel < 2.5.19 - "policy" # 40 Scheduling policy, NULL if kernel < 2.5.19 + "policy", # 40 Scheduling policy, NULL if kernel < 2.5.19 + "delayacct_blkio_ticks" + # 41 Aggregated block I/O delays, NULL if kernel < 2.6.18 ] STATUSLIST = [ @@ -219,16 +221,18 @@ "processor", # 38 CPU number last executed on "rt_priority",# 39 Real-time scheduling priority, NULL if kernel < 2.5.19 "policy", # 40 Scheduling policy, NULL if kernel < 2.5.19 - "size", # 41 total program size - "resident", # 42 resident set size - "share", # 43 shared pages - "text", # 44 text (code) - "lib", # 45 library - "data", # 46 data/stack - "dt", # 47 dirty pages (unused in Linux 2.6) - "wchan", # 48 This is the "channel" in which the process is waiting. - "lastseen", # 49 the unix lohg time this process was last seen - "cmdline" # 50 complete command line for the process, unless the + "delayacct_blkio_ticks", + # 41 Aggregated block I/O delays, NULL if kernel < 2.6.18 + "size", # 42 total program size + "resident", # 43 resident set size + "share", # 44 shared pages + "text", # 45 text (code) + "lib", # 46 library + "data", # 47 data/stack + "dt", # 48 dirty pages (unused in Linux 2.6) + "wchan", # 49 This is the "channel" in which the process is waiting. + "lastseen", # 50 the unix lohg time this process was last seen + "cmdline" # 51 complete command line for the process, unless the # whole process has been swapped out or the process is # a zombie. then its one null char ] @@ -829,7 +833,8 @@ fp = open('/proc/%s/stat' % (self.__pid,), 'r') ln = string.split(fp.read()) # 2.5.19+ has 41 under 2.5.19 have 39 - while len(ln) < 41: + # 2.6.18+ has 42 + while len(ln) < 42: ln.append("-1") fp.close() return ln