Wiki-UX / How to get process thread count
Jump to: navigation, search

How to get process thread count


HP-UX ps command offer no option to obtain the LWP (threads) per process. The following document shows a small ANSI application able to extract the thread value for an individual process


void main()
 pid_t pid;
 struct pst_status pst;
 printf("Enter pid number ... ");
 * First get the desired process to get its 'index'.
 * This will be used when retrieving the file data.
 if (pstat_getproc(&pst, sizeof(pst), (size_t)0, pid) != -1)
  printf("pid is %d, cmd is %s, # threads: %d\n", pst.pst_pid, pst.pst_cmd, pst.pst_nlwps);

Compile numthreads

Save the previous code on numthreads.c text file. On HP-UX running 64 bit kernels, use the following cc sintaxis:

# cc +DD64 -O numthreads.c -o numthreads
file numthreads

# file numthread
numthread: ELF-64 executable object file - PA-RISC 2.0 (LP64)
  • Note: On older HP-UX systems running 32 bit kernels, the +DD64 flag should not be used.

Obtain the number of thread for your process

Use "numthreads" to determinate the number of thread of an application

For example:

# ps -ef | grep [v]xfsd
    root    37     0  0  Sep 15  ?         2:49 vxfsd

# ./numthreads
Enter pid number ... 37
pid is 37, cmd is vxfsd, # threads 22

Observe that the number of threads of vxfsd process is 22.



This page was last modified on 18 September 2008, at 21:43. This page has been accessed 3,214 times.