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?
-
how much portability do you need? or is this only Linux?– thrigOct 8, 2018 at 13:55
-
@thrig not much. It's only Linux and every machine this is deployed on should be the same– NicoOct 8, 2018 at 13:57
1 Answer
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
).
-
Okay, thanks. And if it's there, can I also assume that it will not be temporarily unavailable - even for a very improbable reason?– NicoOct 8, 2018 at 14:12
-
Are you asking me if it is probable for something very improbable to happen?– HkoofOct 8, 2018 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.– HkoofOct 8, 2018 at 14:51
-
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
. Oct 8, 2018 at 19:37