Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 07 Jun 2006 22:18:44 -0700
From:      Maksym Sobolyev <sobomax@sippysoft.com>
To:        Mikhail Teterin <mi+mx@aldan.algebra.com>
Cc:        current@FreeBSD.ORG
Subject:   Re: getrusage() -- negative ru_maxrss?!
Message-ID:  <4487B334.60203@sippysoft.com>
In-Reply-To: <200606071827.24207.mi%2Bmx@aldan.algebra.com>
References:  <200606071827.24207.mi%2Bmx@aldan.algebra.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-current
> To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
>
>   




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4487B334.60203>