2

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?

2
  • how much portability do you need? or is this only Linux?
    – thrig
    Oct 8, 2018 at 13:55
  • @thrig not much. It's only Linux and every machine this is deployed on should be the same
    – Nico
    Oct 8, 2018 at 13:57

1 Answer 1

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

8
  • 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, 2018 at 14:12
  • Are you asking me if it is probable for something very improbable to happen?
    – Hkoof
    Oct 8, 2018 at 14:24
  • No, I'm asking if it's at all possible :-)
    – Nico
    Oct 8, 2018 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, 2018 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. Oct 8, 2018 at 19:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .