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? – thrig Oct 8 '18 at 13:55
  • @thrig not much. It's only Linux and every machine this is deployed on should be the same – Nico Oct 8 '18 at 13:57

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).

|improve this answer|||||
  • 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 8 '18 at 14:12
  • Are you asking me if it is probable for something very improbable to happen? – Hkoof Oct 8 '18 at 14:24
  • No, I'm asking if it's at all possible :-) – Nico Oct 8 '18 at 14:31
  • 1
    As 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 8 '18 at 14:51
  • 1
    Not 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 with hidepid=1. – Austin Hemmelgarn Oct 8 '18 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.