How to get process thread count
From Wiki-UX.info
Abstract
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
numthread.c
void main()
{
pid_t pid;
struct pst_status pst;
printf("Enter pid number ... ");
scanf("%d",&pid);
/*
* 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);
}
else
{
perror("pstat_getproc");
}
}
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.
Reference
- WFM Case: 3603295477
- Viewing Threads per Process - HPUX
- Problem with pstat_getproc
- http://docs.hp.com/en/5991-6426/large_pid_nproc_whitepaper.20070110.pdf