Re: Getting resource usage informations of a process

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tassilo Horn wrote:

> I've written a specialized compression utility (C++). Now I want to
> compare it to some general purpose compressors like gzip, bzip2 and
> compress. CPU time and memory consumption are the main things of
> interest.
> 
> Therefore I tried using GNU time [1] (version 1.7). With it I get the
> correct CPU time, but the memory resources are always zero (%p and %M in
> time's format string). I tested this on Linux 2.4 & 2.6, Mac OS X and
> OpenBSD.
> 
> Then I tried writing a simple replacement [2] which utilizes the
> getrusage() (via wait4()) system call. But with this, the memory
> resources are always zero, too. Looking into GNU time's source code, it
> seems that it uses the same approach, so this was a no-go. ;-)
> 
> Is getrusage()/wait4() broken, or not intended to be used like this?

GNU libc uses mmap(MAP_ANONYMOUS) for large blocks; this isn't
accounted for by conventional Unix resource handling mechanisms
(getrusage, setrlimit etc).

> How can I get correct memory resource usage informations of a (child)
> process (without changing the code of the process' applications)?

Parse /proc/<pid>/maps. Any entries with an inode of zero (other than
the heap and stack regions) correspond to mmap(MAP_ANONYMOUS).

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
-
: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux