[PLUG] Testing files for existence in /proc

Daniel Logghe dzl at frenetic.com
Tue Jan 27 12:49:02 UTC 2004


Alex Daniloff wrote:
> Hello Linux folkz,
> I need to test for existence files in /proc:
> /proc/pid_num/cmdline
> /proc/pid_num/exe
> /proc/pid_num/stat
> The unary file test operators in perl (-r -w -l -z and so on)
> don't work in this case. I believe 'cause these files are not real.
> 
> Could somebody please advise me a better way to check
> these files for existence.

The unary file tests work for me, both in perl and in bash. Perhaps the 
problem is you don't have permisions on the files you're testing. Most 
of the files in /proc/pid/ are readable only by the process owner, so 
even though you can see them if you ls /proc/pid/ testing for their 
existence gives a permision denied error, and returns false.

They are perfectly real files as far as the system is concerned.

Also, if you're just testing for existence perhaps the -e operator would 
be the best choice.




More information about the PLUG mailing list