⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 列表5.21.txt

📁 klinux书籍的配套光盘。可以学习学习。
💻 TXT
字号:
【列表5.21】读取一个进程的stat文件。
type
   // The TProcStat record contains the information stored
   // in the process's stat file.
   // See "man 5 proc" for information on these fields.
   TProcStat = record
      pid          : __pid_t;  // process id
      comm       : String;   // Filename of executable
      state        : char;    // RSDZT
      ppid         : __pid_t;  // parent process ID
      pgrp         : __pid_t;  // process group ID
      session      : integer;  // session id
      tty            : integer;  // tty process uses
      tpgid         : __pid_t;  // pid of tty owner
      flags         : cardinal; //
      minflt         : cardinal; // # of minor faults for process
      cminflt        : cardinal; // # of minor faults for process and children
      majflt         : cardinal; // # of major faults for process
      cmajflt       : cardinal; // # of major faults for process and children
      utime        : cardinal; // time scheduled in user mode
      stime       : cardinal; // time scheduled in kernel mode
      cutime      : cardinal; // time scheduled in user mode, including children
      cstime      : cardinal; // time scheduled in kernel mode, including children
      counter     : integer;  // Next time slice
      priority       : integer;  // current priority, plus 15
      timeout       : cardinal; // time of next timeout
      itrealvalue    : cardinal; // next SIGALRM time
      starttime     : integer;  // time process started
      vsize         : cardinal; // Virtual memory size
      rss          : cardinal; // resident set size
      rlim          : ca.rdinal; // RSS limit
        startcode     : cardinal; // start of code space
        endcode     : cardinal; // end of code space
        startstack    : cardinal; // start of stack address
        kstkesp     : cardinal; // current stack pointer
       kstkeip     : cardinal; // current instruction pointer
       signal       : integer;  // bitmap of pending signals
       blocked     : integer;  // bitmap of blocked signals
       sigignore   : integer;  // bitmap of ignored signals
       sigcatch    : integer;  // bitmap of caught signals
       wchan       : cardinal; // channel
     end;
 // ProcGetStat - Return a TProcStat record that contains the
 // information from the process's stat file.
 function ProcGetStat (pid: __pid_t) : TProcStat;
 const
    // scanf string for stat file
   StatScanfFormat =
       '%d %s %c %d %d %d %d %d %u %u %u %u %u %u %u %u %u %d %d %u '+
       '%u %d %u %u %u %u %u %u %u %u %d %d %d %d %u';
var
   s : TProcStat;
   pcomm : PChar;
   stat : String;
begin
  stat := ProcReadFileString (pid, 'stat');
  // allocate string for executable file name.
// this is longer than absolutely necessary, but that's
  pcomm := StrAlloc (Length (stat));
  try
     sscanf (PChar (stat), StatScanfFormat,
        @s.pid, pcomm,   @s.state,        @s.ppid,
        @s.pgrp,         @s.session,      @s.tty,
        @s.tpgid,         @s.flags,        @s.minflt,
        @s.cminflt,       @s.majflt,        @s.cmajflt,
        @s.utime,        @s.stime,        @s.cutime,
        @s.cstime,       @s.counter,      @s.priority,
        @s.timeout,      @s.itrealvalue,    @s.starttime,
        @s.vsize,        @s.rss,          @s.rlim,
        @s.startcode,    @s.endcode,      @s.startstack,
        @s.kstkesp,      @s.kstkeip,       @s.signal,
        @s.blocked.      @s.sigignore.     @s.sigcatch,
        @s.wchan);
     s.comm := pcomm;
  finally
     StrDispose (pcomm);
  end;
   Result := s;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -