Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-08

How to enumerate list of Linux running processes?

8 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sven Barth
to Frank Church
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

Reply by email

Ludo Brands
to Sven Barth
Show quoted text 15 lines
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.

Ludo

Reply by email

Mark Morgan Lloyd
to Ludo Brands
Ludo Brands wrote 18 lines
> 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]

Reply by email

Marco van de Voort
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 10 lines
> 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:

On FreeBSD it will mostly work, but /proc can be turned off, and that is commonly done on servers to reduce the attack surface. (/proc exposes stuff for debugging like addresses that afaik can be used to attack).

Also on embedded and startup kernels it is sometims turned off.

Parsing "ps" is the best option I think.

# For Linux, ps is normally found in /bin/ps.

FreeBSD too.

Reply by email

Frank Church
to Frank Church: Is there a Lazarus/FPC routine to list the processes running on a Linux system, the…
Frank Church wrote 6 lines
Is there a Lazarus/FPC routine to list the processes running on a Linux system, the equivalent of EnumProcesses + GetCommandLineEx(Pids[x]) on Windows? --

I have checked it and assumed that those in which cat /proc/XXXX/cmdline returns a string are the active process?

Is that right? Some of them return a blank - are they terminated, expired or something?

Show quoted text 5 lines
Frank Church ======================= http://devblog.brahmancreations.com
Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110814/577aaeba/attachment.html>

Reply by email

ik
to Mark Morgan Lloyd: ps parses /proc, but some of the command-line options might vary with distro and version.…

On Sun, Aug 14, 2011 at 13:09, Mark Morgan Lloyd <

Show quoted text 39 lines
wrote: 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.

PS also varied from implementation to implementation. BusyBox have very limited version of PS for example.
I think it's easier to look at PS code and implement one in Pascal then to parse the content PS.

Show quoted text 14 lines
-- Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues] -- ______________________________**_________________ Lazarus mailing list .**freepascal.org http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110814/dd5648c9/attachment.html>

Reply by email

Michael Joyner
to ik

2011/8/14 ik

Show quoted text 26 lines
> 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. > PS also varied from implementation to implementation. BusyBox have very limited version of PS for example. I think it's easier to look at PS code and implement one in Pascal then to parse the content PS.

This also will result in very platform specific code.

> >
--- - Learn to speak Cherokee: http://www.cherokeelessons.com/ - Cherokee Language Help BBS/Chat: http://www.cherokeelessons.com/phpBB3/viewforum.php?f=6 - Cherokee Lessons PDF made with: http://www.lyx.org/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110814/acbda6e8/attachment.html>

Reply by email