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

Mailing lists / fpc-pascal / 2009-09
11 messages · 7 people ·
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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
T. Guilleminot wroteDoes 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
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.
Does anyone know a simple way to check if a Linux process exists/runs (child or not)…
2009/9/21 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)?
You can read all the /proc/%d/cmdline files to search for a specific process.
Henry
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.
2009/9/21 Marco van de Voort :
Oh almost definitely not, I'm sure. There isn't really a good reason to do this, either, except for informational purposes.
Henry
How do you want to identify this process? By name, by pid, ...? Jonas
Thanks.
May be more by name actually.
T. Guilleminot wroteDoes 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
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.
//-------------------------------------------2009/9/21 T. Guilleminot : You can read all the /proc/%d/cmdline files to search for a…
You mean by scanning /proc recursively ?
2009/9/21 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)?
You can read all the /proc/%d/cmdline files to search for a specific process.
Henry
While scanning /proc may not be portable, the question asked is about checking for a…
2009/9/21 :
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
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/