【列表5.18】帮助函数 ProcReadLink和调用他的函数。
// ProcReadLink - return the name of the file that the
// link points to.
function ProcReadLink (pid: __pid_t; const sFile: String): String;
var
buf : array [0..1024] of char;
iLen : Integer;
sFilename : String;
begin
sFilename := Format ('/proc/%d/%s', [pid, sFile]);
iLen := readlink (PChar(sFilename), buf, 1024);
if iLen = -1 then
iLen := 0;
buf[iLen] := #0;
Result := buf;
end;
// ProcGetCwd - return the process's current working directory.
function ProcGetCwd (pid: __pid_t): String;
begin
Result := ProcReadLink (pid, 'cwd');
end;
// ProcGetExe - return the name of the process's executable.
function ProcGetExe (pid: __pid_t): String;
begin
Result := ProcReadLink (pid, 'exe');
end;
// ProcGetRoot - return the process's root directory
function ProcGetRoot (pid: __pid_t): String;
begin
Result := ProcReadLink (pid, 'root');
end;