The only interfaces provided by the Linux kernel to get resource limits are getrlimit()
and /proc/
pid/limits
. getrlimit()
can only get resource limits of the calling process. /proc/
pid/limits
allows you to get the resource limits of any process with the same user id, and is available on RHEL 5.2, RHEL 4.7, Ubuntu 9.04, and any distribution with a 2.6.24 or later kernel.
If you need to support older Linux systems then you will have to get the process itself to call getrlimit()
. Of course the easiest way to do that is by modifying the program, or a library that it uses. If you are running the program then you could use LD_PRELOAD
to load your own code into the program. If none of those are possible then you could attach to the process with gdb and have it execute the call within the process. You could also do the same thing yourself using ptrace()
to attach to the process, insert the call in its memory, etc., however this is very complicated to get right and is not recommended.
With appropriate privileges, the other ways to do this would involve looking through kernel memory, loading a kernel module, or otherwise modifying the kernel, but I am assuming that these are out of the question.