简体   繁体   中英

How to get the memory usage of a process in linux without root permission

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM