» Sign in

An HP Solutions Alliance engineer developed it while he was working in an SAP environment on HP-UX 11i v1.  He observed that a Node would grind to a halt and no new users could logon. A typical workaround was to kill the application processes. He checked the syslog and found the message kthread: table is full. The kernel parameter nkthread was set to 6000, so over time the process had more and more threads. The question was: how to determine the number of threads a process has in order to monitor the behavior of the application.

The following C program creates a list of all processes in the process table of a node and shows in one column the number of threads for any single process. Using this tool, it was possible to identify that the network daemon created a new thread anytime a network problem occurred. A severe network problem was responsible for the logon problems.

#include "sys/param.h"
#include "sys/pstat.h"
int main ( void )
  struct pst_status * psa = NULL;   
  struct pst_status * prc = NULL;    
  struct pst_dynamic  psd;
  long                nproc = 0;      
  long                thsum = 0;       
  long                i;                
  if ( pstat_getdynamic(&psd, sizeof(psd), 1, 0) == -1 )
    (void)perror("pstat_getdynamic failed");
  // Get the number of active processes from pst_dynamic 
  nproc  = psd.psd_activeprocs;  
  psa    = (struct pst_status *)malloc(nproc * sizeof(struct pst_status));
  // Read the info about the active processes into the array 'psa' 
  if ( pstat_getproc(psa, sizeof(struct pst_status), nproc, 0) == -1 )
    (void)perror("pstat_getproc failed");
  (void)printf("\n %5s | %5s |%7s| %5s | %s", "PID", "UID", "Threads", "RSS", "Command");
  // Report the process info as required
  prc = (struct pst_status *)psa;       
  for (i=0; i < nproc; i++) 
    (void)printf("\n %5ld | ", prc->pst_pid);
    (void)printf("%5ld | ", prc->pst_uid);
    (void)printf("%5ld | ", prc->pst_nlwps);
    (void)printf("%5ld | ", prc->pst_rssize);
    (void)printf("%s ", prc->pst_cmd);
    thsum += prc->pst_nlwps;
  (void)printf("\n\n*** %ld processes, %ld threads running\n\n", nproc, thsum);

Manage My AllianceOne Membership

 » Sign in
 » Join AllianceOne
 » Contact us