📄 列表5.19.txt
字号:
【列表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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -