views:

532

answers:

2

On Solaris 10, and in C, I'd like to regularly query numbers like

  • The CPU usage for specific LWPs within that OS process.
  • The memory usage for that OS process.

I already know how to do the latter by opening /proc/pid/psinfo and reading from that (pr_rssize), but is there a way to implement the former?

In the past I have forked off a copy of prstat, parsed the output from that and read it back into my C code. As I'm looking to query more and more of this type of information, this is getting increasingly tedious, and just feels plain wrong. Surely there is a way to do this with some simple C code.

Thanks for any help. NickB

A: 

While you ask for a C solution, maybe you could look into the perl module Solaris::Procfs to see what it does to extract information?

hlovdal
A: 

On Solaris, the lwp-specific ps information can be be obtained by reading /proc/pid/lwp/lwpid/lwpsinfo. This file contains a lwpsinfo structure which includes:

timestruc_t pr_time;      /* cpu time for this lwp */

See proc(4) for additional details.

mark4o
Works nicely. Also using pr_pctcpu in lwpsinfo.
NickB