The only interfaces provided by the Linux kernel to obtain resource limits are getrlimit() and /proc/ PID /limits . getrlimit() can only get the 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 in RHEL 5.2, RHEL 4.7, Ubuntu 9.04 and any distribution with a kernel of 2.6.24 or later.
If you need to support older Linux systems, you will need to make the process itself call getrlimit() . Of course, the easiest way to do this is to change the program or library that it uses. If you run the program, you can use LD_PRELOAD to load your code into the program. If none of them is possible, you can connect to the process using gdb and execute it as part of the process. You can also do the same, using ptrace() to join the process, insert the call into your memory, etc., However, it is very difficult to do it right and is not recommended.
With appropriate privileges, other ways to do this would be to scan the kernel memory, load the kernel module, or some other modification of the kernel, but I assume that is out of the question.
mark4o Sep 06 '09 at 0:45 2009-09-06 00:45
source share