On 4/10/17 17:33 , Cody Mello wrote: > Hi Rob, > > Since pr_size and pr_rssize are size_t's, I'm guessing that they're zero > since the number is too big to represent in 32 bits, so the field is being > made 0 instead. If you compile your C program for 64-bit (-m64 for GCC, I > believe), does the output change?
Specifically, if it's a 32-bit process, we won't represent 64-bit fields in it's proc structure: http://src.illumos.org/source/xref/illumos-gate/usr/src/uts/common/fs/proc/prsubr.c#2483. You probably want to make sure that your program matches the running bitness of the kernel (isainfo -k). Robert > On Mon, Apr 10, 2017 at 5:08 PM, Robert Fisher <[email protected]> wrote: > >> I've been writing some software which parses `/proc` to get process info. >> The original is in Python, but I got some unexpected results and, as I'm >> not the best with Python, assumed it was my bad coding. So, I wrote a bit >> of C to cross-reference, and I get the same results. I just can't >> understand why. >> >> ----- >> #include <stdio.h> >> #include <unistd.h> >> #include <procfs.h> >> #include <fcntl.h> >> >> static void print_info(psinfo_t *buf); >> >> void main(int argc, char **argv) { >> psinfo_t buf; >> int fd; >> char file [1024]; >> snprintf(file, 1024, "/proc/%s/psinfo", argv[1]); >> fd = open(file, O_RDONLY); >> read(fd, &buf, sizeof(psinfo_t)); >> close(fd); >> print_info(&buf); >> } >> >> static void print_info(psinfo_t *buf) { >> printf(" PID: %ld\n", buf->pr_pid); >> printf(" cmd: %s\n", buf->pr_psargs); >> printf("size: %ld\n", buf->pr_size); >> printf(" RSS: %ld\n", buf->pr_rssize); >> } >> >> ----- >> >> Obviously, this code parses a process's psinfo struct, and prints the >> memory usage. On some processes it works just fine: >> >> $ ./psinfo 27481 >> PID: 27481 >> cmd: /usr/sbin/cron >> size: 2132 >> RSS: 720 >> >> $ ./psinfo 8715 >> PID: 8715 >> cmd: /usr/bin/java -Djava.library.path=/usr/local/graylog/bin/../lib/sigar >> -Xms256m >> size: 519536 >> RSS: 412148 >> >> But on others, it always shows zero for memory usage. Every other field >> seems to be correct. >> >> $ ./psinfo 28352 >> PID: 28352 >> cmd: java -Xmx500m -Xms300m -server -verbosegc -XX:-UseParallelOldGC >> -XX:OnOutOfMemo >> size: 0 >> RSS: 0 >> >> $ ./psinfo 27627 >> PID: 27627 >> cmd: /ops/local/mysql/bin/mysqld --defaults-file=/opt/local/ >> etc/mysql/my.cnf >> size: 0 >> RSS: 0 >> >> Examining that last process with prstat: >> >> $ prstat -cp 27627 1 1 >> Please wait... >> PID USERNAME SIZE RSS STATE PRI NICE TIME CPU PROCESS/NLWP >> >> 27627 mysql 619M 379M sleep 28 0 0:01:28 0.0% mysqld/23 >> Total: 1 processes, 23 lwps, load averages: 0.12, 0.15, 0.21 >> >> DTracing that command, I can see prstat only looks at /proc/{pid}/psinfo, >> just like my C example. (At first I suspected it was doing something with >> LWP info.) Looking at the source suggests my code and prstat are doing the >> same thing, but one works and one doesn't. >> >> The "zero memory" processes are always the same ones. Some programs always >> report it, and the others never do. It seems particularly odd to me that >> some JVMs "work" and some don't, and it's always the same ones. I get >> identical results on a Solaris box, right down to the same Java programs >> working or not working. >> >> What's going on here? What am I missing? >> >> TIA, >> >> >> Rob >> *smartos-discuss* | Archives >> <https://www.listbox.com/member/archive/184463/=now> >> <https://www.listbox.com/member/archive/rss/184463/27398174-11508a73> | >> Modify >> <https://www.listbox.com/member/?&> >> Your Subscription <http://www.listbox.com> >> > > ------------------------------------------- smartos-discuss Archives: https://www.listbox.com/member/archive/184463/=now RSS Feed: https://www.listbox.com/member/archive/rss/184463/25769125-55cfbc00 Modify Your Subscription: https://www.listbox.com/member/?member_id=25769125&id_secret=25769125-7688e9fb Powered by Listbox: http://www.listbox.com
