トップ 差分 一覧 ソース 検索 ヘルプ PDF RSS ログイン

Linux、割り込み不可能なスリープ状態の監視スクリプト

[カテゴリ:Linux]
[カテゴリ:PHP]

割り込み不可能なスリープ状態の監視スクリプト(2007/10/03)

はじめに

  • STATがD(割り込み不可能なスリープ状態)のプロセスを減らすことができれば、システム負荷を下げられるはず。
  • ps、topはコマンド実行した瞬間の状況が表示されるだけ。
  • STATがDのプロセスがどの程度発生しているのか視覚化できたらなぁ。

スクリプト概要

ps、topコマンドの簡易機能版といったところだが、
STATがDのプロセスを監視する機能に特化した。

$ ./pps
プロセス監視ツール
  * はデフォルト設定
  -mode=ma  :  ps を定周期で行うイメージ
  -mode=mb  :  プロセスのステータスのみを定周期で表示するイメージ
  -mode=mc  :  top イメージ
  -stat=D   :* ステータスが D を表示
  -stat=DS  :  ステータスが D or S を表示
  -delay=1  :* 周期[s] 0.3s〜
  -n=20     :* 最大表示プロセス数(=表示行数)
  --help    :  この表示

実行例

↓1秒周期でプロセスを監視し、STATがDのプロセスを表示する。
./pps -mode=ma -delay=1

14:40:40 pid( 2204) stat(D ) wchan(sync_buffer)   /sbin/syslogd
14:40:41 pid( 2204) stat(D ) wchan(sync_buffer)   /sbin/syslogd **
14:40:44 pid( 2660) stat(D ) wchan(sync_buffer)   /usr/lib/postfix/master
14:40:44 pid( 5617) stat(D ) wchan(sync_buffer)   pickup -l -t fifo -u -c
14:40:44 pid( 6456) stat(D ) wchan(sync_page)     [pdflush]****************************************************************************
14:42:03 pid( 6456) stat(D ) wchan(sync_page)     [pdflush]***********************
14:42:28 pid( 6456) stat(D ) wchan(sync_buffer)   [pdflush]**************
14:42:43 pid( 6456) stat(D ) wchan(sync_buffer)   [pdflush]****************************************
14:43:25 pid( 1024) stat(D<) wchan(_stext)        [reiserfs/0]
14:43:25 pid( 6456) stat(D ) wchan(sync_buffer)   [pdflush]*********
14:43:36 pid( 1024) stat(D<) wchan(_stext)        [reiserfs/0]
14:43:36 pid( 6456) stat(D ) wchan(sync_buffer)   [pdflush]**************************
14:44:03 pid( 6456) stat(D ) wchan(sync_page)     [pdflush]***************************************
14:44:44 pid( 1025) stat(D<) wchan(_stext)        [reiserfs/1]
14:44:44 pid( 6456) stat(D ) wchan(sync_buffer)   [pdflush]********************
14:45:06 pid( 6456) stat(D ) wchan(sync_page)     [pdflush]
14:45:06 pid( 8842) stat(D ) wchan(ide_do_drive_cmd) /usr/sbin/smartctl -a -A -i /dev/hda
14:45:07 pid( 6456) stat(D ) wchan(sync_page)     [pdflush]
14:45:07 pid( 8842) stat(D ) wchan(ide_do_drive_cmd) /usr/sbin/smartctl -a -A -i /dev/hda
14:45:08 pid( 3947) stat(D ) wchan(sync_page)     [pdflush]
14:45:08 pid( 6456) stat(D ) wchan(sync_page)     [pdflush]
14:45:08 pid( 8842) stat(D ) wchan(ide_do_drive_cmd) /usr/sbin/smartctl -a -A -i /dev/hda
14:45:09 pid( 3947) stat(D ) wchan(sync_page)     [pdflush]
14:45:09 pid( 6456) stat(D ) wchan(sync_page)     [pdflush]
14:45:09 pid( 8842) stat(D ) wchan(ide_do_drive_cmd) /usr/sbin/smartctl -a -A -i /dev/hda
14:45:10 pid( 3947) stat(D ) wchan(sync_page)     [pdflush]
14:45:10 pid( 6456) stat(D ) wchan(sync_page)     [pdflush]
14:45:10 pid( 8842) stat(D ) wchan(ide_do_drive_cmd) /usr/sbin/smartctl -a -A -i /dev/hda
14:45:11 pid( 3947) stat(D ) wchan(_stext)        [pdflush]
14:45:11 pid( 6456) stat(D ) wchan(sync_buffer)   [pdflush]
14:45:11 pid( 8842) stat(D ) wchan(ide_do_drive_cmd) /usr/sbin/smartctl -a -A -i /dev/hda
14:45:12 pid( 1024) stat(D<) wchan(_stext)        [reiserfs/0]
14:45:12 pid( 3947) stat(D ) wchan(_stext)        [pdflush]
14:45:12 pid( 6456) stat(D ) wchan(sync_buffer)   [pdflush]
14:45:12 pid( 8842) stat(D ) wchan(ide_do_drive_cmd) /usr/sbin/smartctl -a -A -i /dev/hda
14:45:13 pid( 3947) stat(D ) wchan(sync_buffer)   [pdflush]
14:45:14 pid( 1024) stat(D<) wchan(_stext)        [reiserfs/0]
14:45:14 pid( 3947) stat(D ) wchan(sync_buffer)   [pdflush]
14:45:15 pid( 3947) stat(D ) wchan(sync_buffer)   [pdflush]
14:45:15 pid( 8884) stat(D ) wchan(sync_buffer)   /usr/sbin/munin-node
14:45:16 pid( 3947) stat(D ) wchan(sync_buffer)   [pdflush]

↓1秒周期でプロセスを監視し、全プロセスのSTATを表示する。
./pps -mode=mb -delay=1

14:29:56 .............................................................................R...............
14:29:57 .................................R...........................................R...............
14:29:58 ..................................R..........................................R...............
14:29:59 ..................................R..........................................R...............
14:30:00 .............................................................................R...............
14:30:01 ...................R.........................................................R..........R.............
14:30:02 ..................................R..........................................R........R............
14:30:03 ..................................R..........................................R........R............
14:30:04 ..................................R..........................................R.....................
14:30:05 .............................................................................R........................
14:30:06 ...............................................................R.............R..........D............
14:30:07 .............................................................................R..........D............
14:30:09 .............................................................................R..........D............
14:30:10 .............................................................................R..........D............
14:30:11 .............................................................................R..........D............
14:30:12 .............................................................................R..........D............
14:30:13 .............................................................................R........................
14:30:14 .............................................................................R.........R............
14:30:15 .............................................................................R........................
14:30:16 .............................................................................R........................
14:30:17 .............................................................................R........................
14:30:18 .............................................................................R........................
14:30:19 .............................................................................R........................
14:30:20 .............................................................................R........................
14:30:21 .............................................................................R........................
14:30:22 .............................................................................R........................
14:30:23 .............................................................................R........................
14:30:24 .............................................................................R........................
14:30:25 .............................................................................R........................
14:30:26 .............................................................................R.........Z............
14:30:27 .............................................................................R.........Z............
14:30:28 .............................................................................R..........D............
14:30:29 .............................................................................R........................
14:30:30 .................................................R...........................R......R.............
14:30:31 .............................................................................R......R.............
14:30:32 .............................................................................R......R.............
14:30:33 .............................................................................R......R.............
14:30:34 .............................................................................R...............
14:30:35 .................R...........................................................R...............
14:30:36 .................R.........................................................D.R...............
14:30:37 .................R...........................................................R...............
14:30:38 .............................................................................R...............
14:30:39 .............................................................................R...............
14:30:40 .................R...........................................................R...............
14:30:41 .................R...........................................................R...............

↓1秒周期でプロセスを監視し、PID単位でSTATがDとRの出現回数をカウントして表示する。
 なお、表示の都度スクリーンをクリアする。
./pps -mode=mc -delay=1 -stat=DS

2007/10/03 14:22:57
  D    R HH:MM:SS   PID S  WCHAN                CMD
 85    1 14:15:39 23647 D  sync_buffer          [pdflush]
 74    0 14:22:57  1024 S< worker_thread        [reiserfs/0]
 52    1 14:22:57  3947 S  pdflush              [pdflush]
 42    2 14:22:57  2204 S  4294967295           /sbin/syslogd
 37    2 13:45:38  1840 D  sync_buffer          [pdflush]
 21    0 14:22:57  1025 S< worker_thread        [reiserfs/1]
 20    0 14:22:57  6456 S  pdflush              [pdflush]
 17    0 13:20:15 27318 D  sync_buffer          [pdflush]
 15   51 14:22:57 20467 S  3443150848           /usr/sbin/apache2 -k start
 13    7 14:22:57  2710 S  _stext               top
  8    0 13:50:26  3985 S  3824799744           /usr/bin/perl -w /usr/share/munin/munin-update
  8    0 14:12:08  6029 D  _stext               sh -c wget -t 1 -T 1 -q -O - --http-user=admin --http-passwd=***** http://192.168.0.1/info_main.html | nkf
  8    0 14:12:08  6030 D  _stext               sh -c wget -t 1 -T 1 -q -O - --http-user=admin --http-passwd=***** http://192.168.0.1/info_main.html | nkf
  8   73 14:22:57 24693 S  3913654272           /usr/sbin/apache2 -k start
  7    0 13:50:20  4238 D  ide_do_drive_cmd     /usr/sbin/smartctl -a -A -i /dev/hda
  7    0 13:55:12  4645 D  ide_do_drive_cmd     /usr/sbin/smartctl -a -A -i /dev/hda
  7    0 14:20:14  6749 D  ide_do_drive_cmd     /usr/sbin/smartctl -a -A -i /dev/hda
  6    0 13:20:12  1714 D  ide_do_drive_cmd     /usr/sbin/smartctl -a -A -i /dev/hda
  6    0 13:25:13  2119 D  ide_do_drive_cmd     /usr/sbin/smartctl -a -A -i /dev/hda

ソースコード

php5で動作します。
php4でもたぶん動くかと。

#!/usr/bin/php
<?php

function help()
{
        print "プロセス監視ツール \n";
        print "  * はデフォルト設定 \n";
        print "  -mode=ma  :  ps を定周期で行うイメージ \n";
        print "  -mode=mb  :  プロセスのステータスのみを定周期で表示するイメージ \n";
        print "  -mode=mc  :  top イメージ \n";
        print "  -stat=D   :* ステータスが D を表示 \n";
        print "  -stat=DS  :  ステータスが D or S を表示 \n";
        print "  -delay=1  :* 周期[s] 0.3s〜 \n";
        print "  -n=20     :* 最大表示プロセス数(=表示行数) \n";
        print "  --help    :  この表示 \n";
        exit();
}

// cliはデフォルトで0なので意味ないが一応
set_time_limit(0);

// /proc/pid/stat の インデックス
define('IX_PID', 0);
define('IX_NAME', 1);
define('IX_STATE', 2);
define('IX_3', 5);
define('IX_4', 4);
define('IX_5', 5);
define('IX_7', 7);
define('IX_NICE', 18);
define('IX_THREADS', 19);

// オプション
if (count($argv) <= 1) {
        help();
}
$_ARG = arguments(
        $argv,
        array(
                'mode'  => 'ma',
                'delay' => 1,
                'stat'  => 'D',
                'n'             => 20,
                'debug' => FALSE,
        )
);
if (!preg_match('/^(ma)|(mb)|(mc)$/', $_ARG['mode'])) help();
if ($_ARG['delay'] < 0.3) help();
if (!preg_match('/^[DRSTZ]+$/', $_ARG['stat'])) help();
if (!is_numeric($_ARG['n']) || $_ARG['n'] < 0) help();
if (!is_bool($_ARG['debug'])) help();

function arguments($argv, $_ARG = array())
{
        foreach ($argv as $arg) {
                if (preg_match('#^-{1,2}([a-zA-Z0-9]*)=?(.*)$#', $arg, $matches)) {
                        $key = $matches[1];
                        switch ($matches[2]) {
                                case '':
                                case 'true':
                                        $arg = true;
                                        break;
                                case 'false':
                                        $arg = false;
                                        break;
                                default:
                                        $arg = $matches[2];
                        }
                        $_ARG[$key] = $arg;
                } else {
                        $_ARG['input'][] = $arg;
                }
        }
        return $_ARG;
}

function var_dump_ex(&$v)
{
        foreach (array_keys($v) as $key) {
                $flg = TRUE;
                if (preg_match('/^HTTP/', $key)) $flg = FALSE;
                if (preg_match('/^GLOBAL/', $key)) $flg = FALSE;
                if (preg_match('/^_/', $key)) $flg = FALSE;
                if (preg_match('/^arg/', $key)) $flg = FALSE;
                if (preg_match('/^opt_/', $key)) $flg = FALSE;
                if ($flg === FALSE) {
                        unset($v[$key]);
                }
        }
        debug_zval_dump($v);
}

main($_ARG);
exit();

// 監視実施
function main($_ARG)
{
        $mc_spool = array();
        while(TRUE) {
//var_dump_ex(get_defined_vars());
                $infos = get_infos($_ARG['mode']);
                if (output($_ARG['mode'], $infos, $_ARG['stat'], $_ARG['debug'], $_ARG['n'], &$mc_spool) === FALSE) {
                        echo "*";
                }
                usleep($_ARG['delay'] * 1000000);
        }
}


// /proc/pid/stat,cmdline,wchan からプロセスの各種情報取得
function get_infos($opt_mode)
{
        clearstatcache();
        $my_pid = posix_getpid();
        $infos = array();
        $list = scandir('/proc');
        foreach ($list as $file) {
//              if ($my_pid == $file) {
//                      continue;
//              }
                if (preg_match('/^[0-9]+$/', $file) !== 1) {
                        continue;
                }
                $file = '/proc/' . $file;
                $info = array(
                        'PATH'          => $file,
                        'TYPE'          => @filetype($file),
                        'STAT'          => '',
                        'CMDLINE'       => '',
                        'WCHAN'         => '',
                );
                if ($info['TYPE'] === FALSE) {
                        if ($opt_debug) { print "\nerr!! type " . $file; }
                        continue;
                }
                if ($info['TYPE'] !== 'dir') {
                        continue;
                }

                $info['STAT']    = @file_get_contents($file . '/stat');
                if ($info['STAT'] === FALSE) {
                        if ($opt_debug) { print "\nerr!! stat " . $file; }
                        continue;
                }

                if ($opt_mode == 'ma' || $opt_mode == 'mc') {

                        $info['CMDLINE'] = @file_get_contents($file . '/cmdline');
                        if ($info['CMDLINE'] === FALSE) {
                                if ($opt_debug) { print "\nerr!! cmdline " . $file; }
                                continue;
                        }

                        $info['WCHAN'] = @file_get_contents($file . '/wchan');
                        if ($info['WCHAN'] === FALSE) {
                                if ($opt_debug) { print "\nerr!! wchan " . $file; }
                                continue;
                        }
                }

                $infos[] = $info;
        }
        return $infos;
}


// 画面出力
function output($opt_mode, $infos, $opt_stat_regex_pattern, $opt_debug, $opt_n, &$mc_spool)
{
        $output_flg = FALSE;
        $tm = date('H:i:s');
        $dttm = date('Y/m/d ').$tm;

        if ($opt_mode == 'mb') {
                print "\n".$tm.' ';
        }
        if ($opt_mode == 'mc') {
                print "\x1b[2J ";       // 画面クリア
                printf("\x1b[%02d;%02dH ",0+1,0+1);     // カーソルを左上へ移動
                print $dttm;
                if ($opt_debug) { print " script used memory:" . memory_get_usage(TRUE); }
                print "\n";
        }
        foreach ($infos as $info) {

                $stat_arr = explode(' ', $info['STAT']);

                $pid = $stat_arr[IX_PID];

                $stat = $stat_arr[IX_STATE];
                if ($opt_mode == 'mb') {
                        if ($stat == 'S') { $stat = '.'; }
                        print $stat;
                        $output_flg = TRUE;
                        continue;
                }
                if ($stat_arr[IX_NICE] < 0) { $stat .= '<'; }
                if ($stat_arr[IX_NICE] > 0) { $stat .= 'N'; }
                //if ($stat_arr[IX_PID] == $stat_arr[IX_4]) { $stat .= 's'; }
                //if ($stat_arr[IX_4] == $stat_arr[IX_7]) { $stat .= '+'; }
                if ($stat_arr[IX_THREADS] > 1) { $stat .= 'l'; }

                $wchan = $info['WCHAN'];

                $name = $info['CMDLINE'];
                if ($name == '') {
                        $name = strtr($stat_arr[IX_NAME], '()', '[]');
                } else {
                        $name = strtr($name, "\x00", ' ');
                }

                if ($opt_mode == 'ma') {
                        if (preg_match('/^['.$opt_stat_regex_pattern.']/', $stat) !== 0) {
                                $wchan = 'wchan(' . $wchan . ')';
                                printf("\n%s pid(%5s) stat(%-2s) %-20s %s", $tm, $pid, $stat, $wchan, $name);
                                $output_flg = TRUE;
                        }
                }
                if ($opt_mode == 'mc') {
                        if (preg_match('/^['.$opt_stat_regex_pattern.']/', $stat) !== 0) {
                                $d_count = 0;
                                $r_count = 0;
                                if (isset($mc_spool[$pid])) {
                                        $d_count = $mc_spool[$pid]['D_COUNT'];
                                        $r_count = $mc_spool[$pid]['R_COUNT'];
                                        unset($mc_spool[$pid]);
                                }
                                if ($stat{0} == 'D') { $d_count ++; }
                                if ($stat{0} == 'R') { $r_count ++; }
                                $msg = sprintf('%s %5s %-2s %-20s %s', $tm, $pid, $stat, $wchan, $name);
                                $wk = array(
                                        'PID'           => $pid,
                                        'MSG'           => $msg,
                                        'D_COUNT'       => $d_count,
                                        'R_COUNT'       => $r_count,
                                );
                                $mc_spool[$pid] = $wk;
                        }
                }
        }
        if ($opt_mode == 'mc') {
                $wk_spool = $mc_spool;
                usort($wk_spool, "st");
                print("   D    R HH:MM:SS   PID S  WCHAN                CMD\n");
                $cnt = 0;
                foreach ($wk_spool as $val) {
                        printf("%4d %4d %s\n", $val['D_COUNT'], $val['R_COUNT'], $val['MSG']);
                        $cnt ++;
                        if ($cnt >= $opt_n) break;
                }
                $output_flg = TRUE;
                unset($wk_spool);
        }
        return $output_flg;
}

function st($a, $b)
{
        if ($a['D_COUNT'] != $b['D_COUNT']) {
                return $a['D_COUNT'] < $b['D_COUNT'];
        }
        return $a['PID'] > $b['PID'];
}

?>

メモ1

  • なんか途中で止まることがある?
    • 動かしてるといつのまにかとまっていたり、起動直後にとまったり。
    • メモリをチェックしようとmemory_get_usage()を使ってるとしばらくたつとマイナス表記になっておどろいた。memory_get_usage(TRUE)なら実際に確保されているメモリ容量になる。
    • よくわからない。-mode=mc のときだけ止まることがあるので、mcのロジックのどこかなのは確か。最初sortまわりかとおもったが、どうも連想配列をガシガシ使ってるあたりというところまでわかったが、現象が再現するミニマムなスクリプトの新規作成がうまくゆかないので。とりあえず保留
  • ncurses使おうとしたがうまくゆかず。
    • そもそもドキュメントがあまりない。
    • 画面クリアとカーソル移動だけなので直接エスケープシーケンス投げるようにした。

メモ2

psのソースみてみた。

$ dpkg -S /bin/ps
procps: /bin/ps
goun@dimension8300:~/tmp003$ sudo apt-get install build-essential fakeroot devscripts
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
build-essential はすでに最新バージョンです。
fakeroot はすでに最新バージョンです。
devscripts はすでに最新バージョンです。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 1 個。
goun@dimension8300:~/tmp003$
goun@dimension8300:~/tmp003$ apt-get source procps
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています... 完了
319kB のソースアーカイブを取得する必要があります。
取得:1 http://cdn.debian.or.jp etch/main procps 1:3.2.7-3 (dsc) [612B]
取得:2 http://cdn.debian.or.jp etch/main procps 1:3.2.7-3 (tar) [282kB]
取得:3 http://cdn.debian.or.jp etch/main procps 1:3.2.7-3 (diff) [36.1kB]
319kB を 0s で取得しました (760kB/s)
gpg: Signature made 2006年09月13日 10時58分05秒 JST using DSA key ID 12CADFA5
gpg: Can't check signature: public key not found
dpkg-source: extracting procps in procps-3.2.7
dpkg-source: unpacking procps_3.2.7.orig.tar.gz
dpkg-source: applying ./procps_3.2.7-3.diff.gz
goun@dimension8300:~/tmp003$
goun@dimension8300:~/tmp003/procps-3.2.7/ps$ grep STAT *
COPYING:EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
common.h:#define needs_for_select (PROC_FILLSTAT | PROC_FILLSTATUS)
output.c: * short   Up  "  PID TTY STAT  TIME COMMAND"
output.c: * user  u up  "USER       PID %CPU %MEM  SIZE   RSS TTY STAT START   TIME COMMAND
output.c: * jobs  j gPp " PPID   PID  PGID   SID TTY TPGID  STAT   UID   TIME COMMAND
output.c: * sig   s p   "  UID   PID SIGNAL   BLOCKED  IGNORED  CATCHED  STAT TTY   TIME COMMAND
output.c: * vm    v r   "  PID TTY STAT  TIME  PAGEIN TSIZ DSIZ  RSS   LIM %MEM COMMAND
output.c: * regs  X p   "NR   PID    STACK      ESP      EIP TMOUT ALARM STAT TTY   TIME COMMAND
output.c:{"stat",      "STAT",    pr_stat,     sr_state,   4,   0,    BSD, TO|LEFT}, /*state,s*/
output.c:{"state",     "S",       pr_s,        sr_state,   1,   0,    XXX, TO|LEFT}, /*stat,s*/ /* was STAT */
output.c:{"status",    "STATUS",  pr_nop,      sr_nop,     6,   0,    DEC, AN|RIGHT},
output.c:{"xstat",     "XSTAT",   pr_nop,      sr_nop,     5,   0,    BSD, AN|RIGHT},
ps.1:The use of BSD\-style options will add process state (stat=STAT) to the
ps.1:.SH "PROCESS STATE CODES"
ps.1:\fBstate\fR output specifiers (header\ "STAT"\ or\ "S") will display to
ps.1:See\ section \fBPROCESS STATE CODES\fR for the different values.
ps.1:stat       STAT    T{
ps.1:See\ section \fBPROCESS STATE CODES\fR
goun@dimension8300:~/tmp003/procps-3.2.7/ps$
$ vi procps-3.2.7/ps/output.c
static int pr_stat(char *restrict const outbuf, const proc_t *restrict const pp){
    int end = 0;
    outbuf[end++] = pp->state;
//  if(pp->rss==0 && pp->state!='Z')  outbuf[end++] = 'W'; // useless "swapped out"
    if(pp->nice < 0)                  outbuf[end++] = '<';
    if(pp->nice > 0)                  outbuf[end++] = 'N';
// In this order, NetBSD would add:
//     traced   'X'
//     systrace 'x'
//     exiting  'E' (not printed for zombies)
//     vforked  'V'
//     system   'K' (and do not print 'L' too)
    if(pp->vm_lock)                   outbuf[end++] = 'L';
    if(pp->session == pp->tgid)       outbuf[end++] = 's'; // session leader
    if(pp->nlwp > 1)                  outbuf[end++] = 'l'; // multi-threaded
    if(pp->pgrp == pp->tpgid)         outbuf[end++] = '+'; // in foreground process group
    outbuf[end] = '\0';
    return end;
}
$ vi procps-3.2.7/proc/readproc.h
typedef struct proc_t {
// 1st 16 bytes
    int
        tid,        // (special)       task id, the POSIX thread ID (see also: tgid)
        ppid;       // stat,status     pid of parent process
    unsigned
        pcpu;           // stat (special)  %CPU usage (is not filled in by readproc!!!)
    char
        state,      // stat,status     single-char code for process state (S=sleeping)
        pad_1,      // n/a             padding
        pad_2,      // n/a             padding
        pad_3;      // n/a             padding
// 2nd 16 bytes
    unsigned long long
    utime,      // stat            user-mode CPU time accumulated by process
    stime,      // stat            kernel-mode CPU time accumulated by process
// and so on...
    cutime,     // stat            cumulative utime of process and reaped children
    cstime,     // stat            cumulative stime of process and reaped children
    start_time; // stat            start time of process -- seconds since 1-1-70
#ifdef SIGNAL_STRING
    char
    // Linux 2.1.7x and up have 64 signals. Allow 64, plus '\0' and padding.
    signal[18], // status          mask of pending signals, per-task for readtask() but per-proc for readproc()
    blocked[18],    // status          mask of blocked signals
    sigignore[18],  // status          mask of ignored signals
    sigcatch[18],   // status          mask of caught  signals
    _sigpnd[18];    // status          mask of PER TASK pending signals
#else
    long long
    // Linux 2.1.7x and up have 64 signals.
    signal,     // status          mask of pending signals, per-task for readtask() but per-proc for readproc()
    blocked,    // status          mask of blocked signals
    sigignore,  // status          mask of ignored signals
    sigcatch,   // status          mask of caught  signals
    _sigpnd;    // status          mask of PER TASK pending signals
#endif
    unsigned KLONG
    start_code, // stat            address of beginning of code segment
    end_code,   // stat            address of end of code segment
    start_stack,    // stat            address of the bottom of stack for the process
    kstk_esp,   // stat            kernel stack pointer
    kstk_eip,   // stat            kernel instruction pointer
    wchan;      // stat (special)  address of kernel wait channel proc is sleeping in
    long
    priority,   // stat            kernel scheduling priority
    nice,       // stat            standard unix nice level of process
    rss,        // stat            resident set size from /proc/#/stat (pages)
    alarm,      // stat            ?
    // the next 7 members come from /proc/#/statm
    size,       // statm           total # of pages of memory
    resident,   // statm           number of resident set (non-swapped) pages (4k)
    share,      // statm           number of pages of shared (mmap'd) memory
    trs,        // statm           text resident set size
    lrs,        // statm           shared-lib resident set size
    drs,        // statm           data resident set size
    dt;     // statm           dirty pages
    dt;     // statm           dirty pages
    unsigned long
    vm_size,        // status          same as vsize in kb
    vm_lock,        // status          locked pages in kb
    vm_rss,         // status          same as rss in kb
    vm_data,        // status          data size
    vm_stack,       // status          stack size
    vm_exe,         // status          executable size
    vm_lib,         // status          library size (all pages, not just used ones)
    rtprio,     // stat            real-time priority
    sched,      // stat            scheduling class
    vsize,      // stat            number of pages of virtual memory ...
    rss_rlim,   // stat            resident set size limit?
    flags,      // stat            kernel flags for the process
    min_flt,    // stat            number of minor page faults since process start
    maj_flt,    // stat            number of major page faults since process start
    cmin_flt,   // stat            cumulative min_flt of process and child processes
    cmaj_flt;   // stat            cumulative maj_flt of process and child processes
    char
    **environ,  // (special)       environment string vector (/proc/#/environ)
    **cmdline;  // (special)       command line string vector (/proc/#/cmdline)
    char
    // Be compatible: Digital allows 16 and NT allows 14 ???
        euser[P_G_SZ],  // stat(),status   effective user name
        ruser[P_G_SZ],  // status          real user name
        suser[P_G_SZ],  // status          saved user name
        fuser[P_G_SZ],  // status          filesystem user name
        rgroup[P_G_SZ], // status          real group name
        egroup[P_G_SZ], // status          effective group name
        sgroup[P_G_SZ], // status          saved group name
        fgroup[P_G_SZ], // status          filesystem group name
        cmd[16];    // stat,status     basename of executable file in call to exec(2)
    struct proc_t
    *ring,      // n/a             thread group ring
    *next;      // n/a             various library uses
    int
    pgrp,       // stat            process group id
    session,    // stat            session id
    nlwp,       // stat,status     number of threads, or 0 if no clue
    tgid,       // (special)       task group ID, the POSIX PID (see also: tid)
    tty,        // stat            full device number of controlling terminal
        euid, egid,     // stat(),status   effective
        ruid, rgid,     // status          real
        suid, sgid,     // status          saved
        fuid, fgid,     // status          fs (used for file access only)
    tpgid,      // stat            terminal process group id
    exit_signal,    // stat            might not be SIGCHLD
    processor;      // stat            current (or most recent?) CPU
} proc_t;

最終更新時間:2007年10月03日 15時21分06秒