Reputation: 471
I am making a site with php in a hosting server, so I don't have root permission. I have to get the max memory usage of a process which is compiled by GCC. I searched all of the possible solutions:
top, vmstat, ps, proc/$pid$/status, valgrind
- permission denied
pmap
- it didn't do anything
How can I get the memory usage of the process without root permission? Please give me some idea. Thanks. :)
Upvotes: 3
Views: 1490
Reputation: 13216
I'm not sure exactly what you are really looking for-- do you want to know the amount of memory that a process is currently using? If so, then look at /proc/<pid>/status
and examine the VmRSS line. That's the number you want (in this case, RSS means "Resident Set Size" if you're curious). That line should be parse-able in a high-level language like PHP. However, for a lower-level language like C, it should be easier to parse /proc/<pid>/stat
which has the same values but each is separated by a space and there are no labels.
If you don't have permission to read the file, that means that the server process is running under a different user than you are logged in as. You will need to work with the hosting provider to get that resolved, or figure out how to get the server process to query its own processes (PHP script?).
Does that answer your question? Or are you interested in knowing "max memory usage" as in, "the most amount of memory that a process may use before being killed by the kernel?" This is actually something of a touchy philosophical issue for Linux. You won't find any solid information about such a maximum because there is no hard limit. Read up on "Linux memory overcommit" for more details.
Upvotes: 1