I'm developing a script that will monitor several machines, notably by reading from /proc/[vmstat|stat|diskstats|net/dev]
and I'm wondering if I can assume those will always be accessible and readable or if I should check whether the read went well. Any advice?
Asked
Active
Viewed 242 times
2
-
how much portability do you need? or is this only Linux? – thrig Oct 08 '18 at 13:55
-
@thrig not much. It's only Linux and every machine this is deployed on should be the same – Nico Oct 08 '18 at 13:57
1 Answers
4
Strictly speaking, you cannot count on /proc to be there. Very security minded admins my chose not to even mount it.
But if it is there, it's quite safe to assume everybody can read it. Quite a few very common command line tools depend on /proc, (e.g. ps
, top
).

Hkoof
- 1,667
-
Okay, thanks. And if it's there, can I also assume that it will not be temporarily unavailable - even for a very improbable reason? – Nico Oct 08 '18 at 14:12
-
Are you asking me if it is probable for something very improbable to happen? – Hkoof Oct 08 '18 at 14:24
-
-
1As a linux sysadmin for over 10 years, I never saw it happen in 200+ machines. I'd say only a serious disk or admin failure, or an unlikely, big kernel bug could cause /proc to be suddenly temporarily unavailable just like that. – Hkoof Oct 08 '18 at 14:51
-
I saw it happen once, after not adding it to /etc/mount after installing linux compatability on a BSD (unix) server. Only time I saw it not being there though. – Hennes Oct 08 '18 at 15:41
-
1Not quite true, you may not be able to read the contents of
/proc/$PID
directories you don't own. It's not common, but some people do mount/proc
withhidepid=1
. – Austin Hemmelgarn Oct 08 '18 at 19:37 -
@Austin Hemmelman: that, and "[...] it will not be temporarily unavailable" are not exactly the same thing. – Hkoof Oct 09 '18 at 06:25
-
I should have clarified, I was commenting on the 'If it's there, it's quite safe to assume everybody can read it.' bit in the answer itself. It's still technically safe, but you need to handle -EPERM errors correctly. – Austin Hemmelgarn Oct 09 '18 at 11:45