列表5.19.txt

来自「klinux书籍的配套光盘。可以学习学习。」· 文本 代码 · 共 42 行

TXT
42
字号
【列表5.19】枚举一个进程的所有文件。
      type
         // Process file enumeration callback.
        TProcFileEnumCallback = procedure (pid: __pid_t;
           fd: Integer) of object;
     {
        ProcEnumFiles - Enumerate the files used by the process.
        If the calling process does not have permissions to
        access the fd directory for this process, no FDs will
        be enumerated.
    }
    procedure ProcEnumFiles (pid: __pid_t; cb: TProcFileEnumCallback);
    var
       sr : TSearchRec;
       findRslt : Integer;
       sFilename : String;
       fd : Integer;
   begin
      sFilename := Format ('/proc/%d/fd/*,, [pid]);
      findRslt := FindFirst (sFilename, faAnyFile, sr);
      try
         while findRslt = 0 do
        begin
           try
              fd := StrToInt (sr. Name);
           except
              fd := -1;
           end;
           if fd <> -1 then
             cb (pid, fd);
          findRslt := FindNext (sr);
       end;
    finally
       FindClose (sr);
    end;
end;
// ProcGetFD - return the contents of the link for file fd.
function  ProcGetFD (pid: __pid_t; fd: Integer): String;
begin
   Result := ProcReadLink (pid, Format ('fd/%d,[fd]));
end;                                          

⌨️ 快捷键说明

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