Date: Mon, 27 Aug 2007 11:44:33 -0700 From: Frank Mayhar <frank@exit.com> To: hackers@freebsd.org Subject: Getrusage(2) weirdness. Message-ID: <1188240273.84988.13.camel@jill.exit.com>
next in thread | raw e-mail | index | archive | help
I recently had occasion to need the ru_maxrss field returned from getrusage(2) in Linux 2.6, which as it happens was not implemented. So I implemented it. In the process I wrote a test program to validate my implementation. I also tried running the test under various other operating systems, including FreeBSD 6-stable. Most systems don't implement the field (including Solaris and MacOSX), FreeBSD is one of the few that does. Only, it does so weirdly. You can find the test program at http://www.exit.com/Archives/Linux/getrusage-test.c The output should be pretty self-explanatory. If you run it under FreeBSD 6.2 (at least), you will find that it give inconsistent results. Something like the following: jill ~>./getrusage-test before 0 after: 0 1: rusage_self: FAIL flag 6 granddad 0, kid1 0, kid2 0, kid3 0 kid4 0 kid5 2372 sz 1365 2: rusage_grandchildren: PASS flag 3 dad 0, kid1 2372, kid2 2372, kid3 2372 kid4 2372 sz 2048 3: rusage_children: FAIL flag 3 dad 0, kid1 2372, kid2 2372, kid3 2372 kid4 2372 sz 4096 4: rusage_ignorechildren: PASS jill ~>./getrusage-test before 0 after: 968 1: rusage_self: FAIL flag 6 granddad 968, kid1 0, kid2 0, kid3 0 kid4 0 kid5 0 sz 1365 2: rusage_grandchildren: FAIL flag 3 dad 968, kid1 0, kid2 0, kid3 0 kid4 3572 sz 2048 3: rusage_children: PASS flag 3 dad 1820, kid1 3572, kid2 3572, kid3 3572 kid4 3572 sz 4096 4: rusage_ignorechildren: PASS jill ~>./getrusage-test before 0 after: 0 1: rusage_self: FAIL flag 6 granddad 0, kid1 0, kid2 0, kid3 0 kid4 0 kid5 2336 sz 1365 2: rusage_grandchildren: PASS flag 3 dad 1760, kid1 2336, kid2 2336, kid3 2336 kid4 2336 sz 2048 3: rusage_children: FAIL flag 3 dad 1760, kid1 2336, kid2 2336, kid3 2336 kid4 2336 sz 4096 4: rusage_ignorechildren: PASS jill ~>./getrusage-test before 0 after: 1144 1: rusage_self: PASS flag 6 granddad 1144, kid1 0, kid2 0, kid3 0 kid4 0 kid5 0 sz 1365 2: rusage_grandchildren: FAIL flag 3 dad 1144, kid1 0, kid2 0, kid3 0 kid4 0 sz 2048 3: rusage_children: FAIL flag 3 dad 1144, kid1 0, kid2 0, kid3 0 kid4 0 sz 4096 4: rusage_ignorechildren: PASS jill ~>./getrusage-test before 0 after: 0 1: rusage_self: FAIL flag 6 granddad 0, kid1 0, kid2 0, kid3 0 kid4 0 kid5 1936 sz 1365 2: rusage_grandchildren: PASS flag 3 dad 1760, kid1 1936, kid2 1936, kid3 1936 kid4 1936 sz 2048 3: rusage_children: FAIL flag 3 dad 1760, kid1 1936, kid2 1936, kid3 1936 kid4 1936 sz 4096 4: rusage_ignorechildren: PASS jill ~>./getrusage-test before 0 after: 0 1: rusage_self: FAIL flag 6 granddad 0, kid1 0, kid2 0, kid3 0 kid4 0 kid5 0 sz 1365 2: rusage_grandchildren: FAIL flag 3 dad 0, kid1 0, kid2 0, kid3 0 kid4 3052 sz 2048 3: rusage_children: PASS flag 3 dad 0, kid1 3052, kid2 3052, kid3 3052 kid4 3052 sz 4096 4: rusage_ignorechildren: PASS jill ~>./getrusage-test before 0 after: 0 1: rusage_self: FAIL flag 6 granddad 0, kid1 0, kid2 0, kid3 0 kid4 0 kid5 0 sz 1365 2: rusage_grandchildren: FAIL flag 3 dad 0, kid1 0, kid2 0, kid3 0 kid4 3208 sz 2048 3: rusage_children: PASS flag 3 dad 0, kid1 3208, kid2 3208, kid3 3208 kid4 3208 sz 4096 4: rusage_ignorechildren: PASS jill ~>./getrusage-test before 492 after: 492 1: rusage_self: FAIL flag 6 granddad 492, kid1 0, kid2 0, kid3 0 kid4 0 kid5 0 sz 1365 2: rusage_grandchildren: FAIL flag 3 dad 492, kid1 0, kid2 0, kid3 0 kid4 0 sz 2048 3: rusage_children: FAIL flag 3 dad 492, kid1 0, kid2 0, kid3 0 kid4 0 sz 4096 4: rusage_ignorechildren: PASS jill ~>./getrusage-test before 444 after: 444 1: rusage_self: FAIL flag 6 granddad 444, kid1 0, kid2 0, kid3 0 kid4 0 kid5 0 sz 1365 2: rusage_grandchildren: FAIL flag 3 dad 444, kid1 0, kid2 0, kid3 0 kid4 0 sz 2048 3: rusage_children: FAIL flag 3 dad 444, kid1 0, kid2 0, kid3 0 kid4 0 sz 4096 4: rusage_ignorechildren: PASS -- Frank Mayhar frank@exit.com http://www.exit.com/ Exit Consulting http://www.gpsclock.com/ http://www.exit.com/blog/frank/ http://www.zazzle.com/fmayhar*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1188240273.84988.13.camel>