getrusage() -- negative ru_maxrss?!

Maksym Sobolyev sobomax at sippysoft.com
Thu Jun 8 07:50:14 UTC 2006


Looks like you are just overflowing long, which is 32bits on i386. You 
are multiplying size in kilobytes by 4K, in 32 bit math, which as it can 
be easily seen will overflow 2^^31 limit and therefore go negative when 
maxrss is more than 512K.

-Maxim

Mikhail Teterin wrote:
> Hello!
>
> I have a program, which uses getrusage() to report its own performance before 
> exiting.
>
> I noticed recently, that the ru_maxrss field is sometimes reported negative -- 
> I don't think, I ever saw this last year, for example... Is the field 
> considered usable and (semi-)accurate, or did FreeBSD abandon it (as Solaris 
> did)?
>
> I currently print it as:
>
> 	fprintf(..., "... used %ld Kb ...", ... ru.ru_maxrss*getpagesize()/1024... );
>
> What's the right way to do it?
>
> 	-mi
> _______________________________________________
> freebsd-current at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe at freebsd.org"
>
>   



More information about the freebsd-current mailing list