[Lazarus] RE : How to enumerate list of Linux running processes?
Mark Morgan Lloyd
markMLl.lazarus at telemetry.co.uk
Sun Aug 14 12:09:48 CEST 2011
Ludo Brands wrote:
>> On 13.08.2011 23:11, Frank Church wrote:
>>> Is there a Lazarus/FPC routine to list the processes running on a
>>> Linux system, the equivalent of EnumProcesses +
>>> GetCommandLineEx(Pids[x]) on Windows?
>> There is no cross platform way for that so you either need to
>> list the
>> files in "/proc" (those directories that contain only a number are
>> processes) or parse the output of e.g. "top". "top" itself
>> afaik scans
>> "/proc" as well.
>>
>> Regards,
>> Sven
>>
> Perhaps parsing the ps output is easier since output is already quite
> configurable. ps is also parsing /proc.
> As long as you stick to linux, this solution can be made portable between
> the different flavors. Portablility with other unix's is problematic.
ps parses /proc, but some of the command-line options might vary with
distro and version. I've used it reasonably successfully on Linux and
Solaris, my notes from a Perl script:
# For Linux, ps is normally found in /bin/ps. For Solaris it is probably in
# /usr/bin/ps, but we never want to use the Berkeley one in /usr/ucb/ps
which
# has neither the --ppid nor the -f option; code below will probably need to
# be refined for BSD.
I had my "new" SGI system running IRIX briefly yesterday, and could see
numbered entries in /proc. I didn't investigate the content, or what ps
was like.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the Lazarus
mailing list