3

I have a multi-threaded application(C++ and pthread library) and I will like to know how much resources(CPU and memory) each thread uses. Is there a way to find out these details on Solaris and Linux both or on either of them.

2
  • For linux there's an exact duplicate(stackoverflow.com/questions/1431569/…). Commented Oct 5, 2009 at 10:23
  • I checked this out beforehand. My question was also for Solaris. Have not found any thing yet. Only thing i can conclude now is that talking about memory consumption per thread is not a good idea as they share the same memory space. May be we can only calculate what memory was allocated or deallocated by a thread (How to do this ??). Commented Oct 6, 2009 at 6:19

1 Answer 1

7

You could use the ps command with some option:

 ps -eLo pid,ppid,lwp,nlwp,osz,rss,ruser,pcpu,stime,etime,args | more PID PPID LWP NLWP SZ RSS RUSER %CPU STIME ELAPSED COMMAND 0 0 1 1 0 0 root 0.0 Oct_02 4-02:13:37 sched 1 0 1 1 298 528 root 0.0 Oct_02 4-02:13:36 /sbin/init 2 0 1 1 0 0 root 0.0 Oct_02 4-02:13:36 pageout 

Have a look at the ps man's page to get some information (LWP (light weight process))

Sign up to request clarification or add additional context in comments.

3 Comments

Is LWP a thread? I mean in Linux/Solaris terms. Since in what you have pasted here PPID is 0, I suppose that its a process and not a thread. Am I correct?
As far as i can tell - the pcpu flag gives CPU usage for the process, not for the LWP.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.