- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Off-by-one problem for psd_activeprocs in psta...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2011 07:17 AM
09-27-2011 07:17 AM
psd_activeprocs seems to be off-by-one on 11iv1, always returning 1 less than the actual number of active processes. I can't find a patch that addresses this either.
#include <stdlib.h> #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,j; 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; nproc = psd.psd_numprocsallocd; printf("\nNum Procs Allocd = %d, Active procs = %d , psd_maxprocs = %d\n", psd.psd_numprocsallocd, psd.psd_activeprocs, psd.psd_maxprocs); 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\n------------------------------------------------------------------------------"); (void)printf("\n %5s | %5s | %5s |%7s| %5s | %s", "INDEX", "PID", "UID", "Threads", "RSS", "Command"); (void)printf("\n------------------------------------------------------------------------------"); // Report the process info as required prc = (struct pst_status *)psa; for (i=0,j=0; i < nproc; i++,j++) { if (prc->pst_pid == 0 && prc->pst_uid == 0 && prc->pst_nlwps == 0 ) break; (void)printf("\n %5ld | ", i); (void)printf("%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; ++prc; } (void)printf("\n\n*** %ld processes reported by pstat, %ld threads running, %ld procs scanned\n\n", psd.psd_activeprocs, thsum, j); (void)free(psa); (void)exit(0); }
cc +DD64 -D_PSTAT64 -z -Ae -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE -lnm -lxnet -g -o g3 g3.c
Output on 11iv1:
*** 119 processes reported by pstat, 255 threads running, 120 procs scanned
Output on 11iv3:
*** 266 processes reported by pstat, 904 threads running, 266 procs scanned
Solved! Go to Solution.
- Tags:
- pstat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-27-2011 07:36 AM
09-27-2011 07:36 AM
Re: Off-by-one problem for psd_activeprocs in pstat_getdynamic on 11iv1 ?
Hi:
Interestingly, in 11.23, PHKL_35181 fixes incorrect values for 'psd_activeprocs' among others when calling 'pstat_getdynamic(2)'.
Since 11.11 is no longer actively patched, you may be stuck, though you could contact the Response Center and ask about your options.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2011 03:34 AM
10-01-2011 03:34 AM
Solution>psd_activeprocs seems to be off-by-one on 11.11, always returning 1 less than the actual number of active processes.
Hmm, I thought I saw it match once??
> if (prc->pst_pid == 0 && prc->pst_uid == 0 && prc->pst_nlwps == 0 )
This logic isn't needed. You should simply use the result of:
count = pstat_getproc(psa, sizeof(struct pst_status), nproc, 0)
>PHKL_35181 fixes incorrect values for 'psd_activeprocs' among others when calling 'pstat_getdynamic(2)'.
This mentions vPars and deactivating a CPU, which I don't have.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2011 07:07 AM
10-03-2011 07:07 AM
Re: Off-by-one problem for psd_activeprocs in pstat_getdynamic on 11.11?
Thank you both.
Interestingly, it's off by one on 11.0, v1, and v2. v3 returns the correct value.
I modified the code to allocate (psd.psd_activeprocs+10) structures, and used the count returned by pstat_getproc, which works across all 4 versions.
Earl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2011 01:12 PM - edited 10-04-2011 02:18 AM
10-03-2011 01:12 PM - edited 10-04-2011 02:18 AM
Re: Off-by-one problem for psd_activeprocs in pstat_getdynamic on 11.11?
>Interestingly, it's off by one on 11.00, 11.11, and 11.23. 11.31 returns the correct value.
I guess I didn't try 11.23, I'll do that later.
(Yes it fails the same way.)
>I modified the code to allocate (psd.psd_activeprocs+10) structures, and used the count returned by pstat_getproc
If you look at the man page examples, you can do multiple requests with smaller chunks.