mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-04 07:42:59 +02:00
debugger: add pid enumeration code for linux
git-svn-id: trunk@43286 -
This commit is contained in:
parent
499e77cc8b
commit
d15212e123
@ -89,11 +89,59 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$else}
|
{$else}
|
||||||
|
{$ifdef linux}
|
||||||
|
uses
|
||||||
|
LazUTF8Classes;
|
||||||
|
|
||||||
|
function EnumerateProcesses(AList: TRunningProcessInfoList): boolean;
|
||||||
|
|
||||||
|
function GetProcName(Pid: THandle): String;
|
||||||
|
var
|
||||||
|
S: TStream;
|
||||||
|
Sz: Integer;
|
||||||
|
begin
|
||||||
|
S := TFileStreamUTF8.Create('/proc/' + IntToStr(Pid) + '/cmdline', fmOpenRead or fmShareDenyNone);
|
||||||
|
try
|
||||||
|
SetLength(Result, 255);
|
||||||
|
Sz := S.Read(Result[1], 255);
|
||||||
|
SetLength(Result, Sz);
|
||||||
|
finally
|
||||||
|
S.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Rec: TSearchRec;
|
||||||
|
ProcName: String;
|
||||||
|
Pid: THandle;
|
||||||
|
Code: Integer;
|
||||||
|
item: TRunningProcessInfo;
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
|
||||||
|
if not Assigned(AList) then
|
||||||
|
Exit;
|
||||||
|
|
||||||
|
if FindFirstUTF8('/proc/*', faDirectory, Rec) = 0 then
|
||||||
|
begin
|
||||||
|
repeat
|
||||||
|
Val(Rec.Name, Pid, Code);
|
||||||
|
if (Code = 0) then
|
||||||
|
begin
|
||||||
|
ProcName := GetProcName(Pid);
|
||||||
|
item := TRunningProcessInfo.Create(Pid, ProcName);
|
||||||
|
AList.Add(item);
|
||||||
|
end;
|
||||||
|
until FindNextUTF8(Rec) <> 0;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$else}
|
||||||
function EnumerateProcesses(AList: TRunningProcessInfoList): boolean;
|
function EnumerateProcesses(AList: TRunningProcessInfoList): boolean;
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
end;
|
end;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
{$endif}
|
||||||
|
|
||||||
{ TRunningProcessInfo }
|
{ TRunningProcessInfo }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user