[fpc-pascal] Checking Linux process existence (child or not) without OS command ?

Henry Vermaak henry.vermaak at gmail.com
Mon Sep 21 16:56:32 CEST 2009

2009/9/21  <fpclist at silvermono.co.za>:
> 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.


More information about the fpc-pascal mailing list