Zitat(I.I @ 10 Aug 2009, 15:30)
file_exists:
Die Ergebnisse dieser Funktion werden gecached. Weitere Details erhalten Sie bei clearstatcache().
für file_exists('/proc/'.$pid) muss file_exists doch auch auf /proc/ zugreifen können oder seh ich das falsch? @mmarx
Klar ist das ne einfache elegante variante aber ich frag mich wo das problem ist meine Variante zu benutzen :-).

FYI:
strace -s512 ps ax
[...]
stat64("/proc/15", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0
open("/proc/15/stat", O_RDONLY) = 6
read(6, "15 (ata_aux) S 2 0 0 0 -1 2149621824 0 0 0 0 0 0 0 0 15 -5 1 0 54 0 0 4294967295 0 0 0 0 0 0 0 2147483647 0 3222581877 0 0 17 0 0 0 0 0 0\n"..., 1023) = 138
close(6) = 0
open("/proc/15/status", O_RDONLY) = 6
read(6, "Name:\tata_aux\nState:\tS (sleeping)\nTgid:\t15\nPid:\t15\nPPid:\t2\nTracerPid:\t0\nUid:\t0\t0\t0\t0\nGid:\t0\t0\t0\t0\nFDSize:\t32\nGroups:\t\nThreads:\t1\nSigQ:\t0/8187\nSigPnd:\t0000000000000000\nShdPnd:\t0000000000000000\nSigBlk:\t0000000000000000\nSigIgn:\tffffffffffffffff\nSigCgt:\t0000000000000000\nCapInh:\t0000000000000000\nCapPrm:\tffffffffffffffff\nCapEff:\tfffffffffffffeff\nCapBnd:\tffffffffffffffff\nCpus_allowed:\tffffffff,ffffffff\nCpus_allowed_list:\t0-63\nMems_allowed:\t1\nMems_allowed_list:\t0\nvoluntary_ctxt_switches:\t2\nnonvoluntary_ctxt_switches"..., 1023) = 517
close(6) = 0
open("/proc/15/cmdline", O_RDONLY) = 6
read(6, ""..., 2047) = 0
close(6) = 0
write(1, " 15 ? S< 0:00 [ata_aux]\n"..., 37 15 ? S< 0:00 [ata_aux]
) = 37
[...]
lsof nimmt auch /proc. Darüberhinaus macht lsof (sogar im Vergleich zu ps) eine ganze _MENGE_ mehr overhead (ps == 3 (sh, ps, grep) mal fork/execve - sick - aber lsof dürfte noch irrer sein!). file_exists() und /proc/pid/cmdline sind die sinnvollen wie auch deutlich schnelleren und weniger overhead verursachenden Alternativen.
@seb: Wie bereits erwähnt: Randomisierte PID Erzeugung ist durchaus verbreitet.