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

📄 列表5.16.txt

📁 klinux书籍的配套光盘。可以学习学习。
💻 TXT
字号:
【列表5.16】读一个进程的cmdline 文件。
{
   ProcReadFile reads the contents of the specified file
   for the passed process id, and returns the contents in the
   supplied buffer. On entry, length contains the size of
   the buffer. On exit, length contains the number of bytes
   read. The function returns 0 on success, -1 on error.
  }
     function  ProcReadFile (pid: __pid_t; const path: String;
        var buffer; var length: Integer): integer;
     var
        sFileName : String;
        fd : Integer;
    begin
       Result := -1;
       try
          sFileName := Format ('/proc/%d/%s,, [pid, path]);
          fd := Libc.open (PChar (sFilename), 0_RDONLY);
          if fd <> -1 then
          begin
            try
               Result := Libc. __read (fd, Buffer, length);
            finally
               Libc. __close(fd);
            end;
         end;
      except
         // swallow exception...
     end;
  end;
  {
     ProcReadFileString returns the entire contents of the specified
     file in a string.
  }
  function ProcReadFileString (pid: _pid_t;
    const path: String): String;
 var
    buffer : array [0..16000] of char;
    length : Integer;
 begin
    length := sizeof (buffer)-1;
    length := ProcReadFile (pid, path, buffer, length);
    if length = -1 then
      Result := ',
   else
   begin
      buffer[length] := #0;
      Result := buffer;
   end;
end;
// ProcGetCmdline - return the command line that. launched the process.
function ProcGetCmdline (pid: __pid_t) : String;
begin
   Result := ProcReadFileString (pid, 'cmdline');
end;

⌨️ 快捷键说明

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