Sign in Join

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

Mailing lists / fpc-pascal / 2009-09

Checking Linux process existence (child or not) without OS command ?

11 messages · 7 people ·

Reply by email Subscribe to this list Your subscription

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

T. Guilleminot

Hi,

Does anyone know a simple way to check if a Linux process exists/runs (child or not) *without* running an OS command via TProcess (or other)?

Thanks.
Tom

Reply by email

Jonas Maebe
to T. Guilleminot
T. Guilleminot wrote
Does anyone know a simple way to check if a Linux process exists/runs (child or not) *without* running an OS command via TProcess (or other)?

How do you want to identify this process? By name, by pid, ...?

Jonas

Reply by email

David W Noon
to T. Guilleminot: Does anyone know a simple way to check if a Linux process exists/runs (child or not)…

On Mon, 21 Sep 2009 14:58:20 +0200 (CEST), T. Guilleminot wrote about [fpc-pascal] Checking Linux process existence (child or not) without OS command ?:

Does anyone know a simple way to check if a Linux process exists/runs (child or not) *without* running an OS command via TProcess (or other)?

One word: procfs

I don't know how you plan to identify the process: by program name, process id., parent process id., or running as a specific userid.

Whatever you choose, you scan /proc and its subdirectories to see everything else that is running in userspace under Linux. All the entries can be treated as text files of directories.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================

Reply by email

Marco van de Voort
to Henry Vermaak

In our previous episode, Henry Vermaak said:

> Does anyone know a simple way to check if a Linux process exists/runs > (child or not) *without* running an OS command via TProcess (or other)? You can read all the /proc/%d/cmdline files to search for a specific process.

While it might work, it won't port well to other unices.

Reply by email

Henry Vermaak
to Marco van de Voort

2009/9/21 Marco van de Voort :

Show quoted text 7 lines
In our previous episode, Henry Vermaak said: > > Does anyone know a simple way to check if a Linux process exists/runs > > (child or not) *without* running an OS command via TProcess (or other)? > > You can read all the /proc/%d/cmdline files to search for a specific process. While it might work, it won't port well to other unices.

Oh almost definitely not, I'm sure. There isn't really a good reason to do this, either, except for informational purposes.

Henry

Reply by email

Unknown author
to T. Guilleminot: Does anyone know a simple way to check if a Linux process exists/runs (child or not)…

While scanning /proc may not be portable, the question asked is about checking for a running Linux process. The only way I know is scanning all directories within /proc (which as you all know are the id's of the running processes) and checking for the process file name and the process command line. If a match is found, you can assume that the process is acknowledged by the kernel as running, although the process could be a zombie process. You can then further deduce whether the latter is the case by scanning /proc/xxx/~cwd which will be unreadable (unable to be openned) if the process is a zombie process.

If someome has a better way, please tell.

//-------------------------------------------
T. Guilleminot wrote 11 lines
Hi, Does anyone know a simple way to check if a Linux process exists/runs (child or not) *without* running an OS command via TProcess (or other)? Thanks. Tom _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Henry Vermaak
to Unknown author: While scanning /proc may not be portable, the question asked is about checking for a…

2009/9/21 :

Show quoted text 11 lines
While scanning /proc may not be portable, the question asked is about checking for a running Linux process. The only way I know is scanning all directories within /proc (which as you all know are the id's of the running processes) and checking for the process file name and the process command line. If a match is found, you can assume that the process is acknowledged by the kernel as running, although the process could be a zombie process. You can then further deduce whether the latter is the case by scanning  /proc/xxx/~cwd which will be unreadable (unable to be openned) if the process is a zombie process. If someome has a better way, please tell.

It really depends what you want to do. The problem with this method is that you are checking for file names, which can easily be changed, so it's not fool proof. You can check the pid files in /var/run (as start-stop-daemon uses), or there are lock files for some processes. You can check if a server is started by simply trying to connect to it. All of this very implementation dependent stuff.

Henry

Reply by email

Graeme Geldenhuys
to Marco van de Voort: In our previous episode, Henry Vermaak said: While it might work, it won't port well to…

2009/9/21 Marco van de Voort :

While it might work, it won't port well to other unices.

Well, the original poster did mention a "Linux process", so there is probably no reason to port it to other unixes. Not all programs need to be portable to other OS's.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email