Operating System - HP-UX
1822504 Members
2455 Online
109642 Solutions
New Discussion юеВ

pstat_getproc - Variation of string length of pst_ucomm

 
SOLVED
Go to solution
a_vinodkrishna
New Member

pstat_getproc - Variation of string length of pst_ucomm

Hi All,
pstat_getproc returns the process name through the pst_ucomm struct member. On some installations of 11.11i, the process name seems to be truncating with only 13 chars and on (most) other installations of 11.11i, the process name comes in as 14 chars.
Could any one please let me know if such they had faced such issues and the workaround / solution for this?

Thanks in advance, Vinod.

PS: I found below link which talks about this, but not completely suggests a solution - http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=195283

Stub (testPstat.c) and results below:

#include
#include
#include
#include
int main ()
{
struct pst_status ProcStat_t;
int Status_i = -1;
errno=0;

Status_i = pstat_getproc (&ProcStat_t, sizeof(ProcStat_t), 0, getpid());

if ( -1 == Status_i || 0 != errno )
{
printf ("Failed to execute pstat_getproc. Status : [%d]\t\t Errno : [%d]\t\t Error Desc : [%s]\n",
Status_i, errno, strerror(errno) );
exit (-1);
}
else
{
printf ("Proc Name : [%s]\n", ProcStat_t.pst_ucomm);
}
}
Server 1:
$: uname -a
HP-UX B.11.11 U 9000/800 <>
$: cc testPstat.c -o testPstattestPstat
$: ./testPstattestPstat
Proc Name : [testPstattestP]

Server 2:
$: uname -a
HP-UX B.11.11 U 9000/800 <>
$: cc testPstat.c -o testPstattestPstat
$: ./testPstattestPstat
Proc Name : [testPstattest]
5 REPLIES 5
Peter Godron
Honored Contributor

Re: pstat_getproc - Variation of string length of pst_ucomm

Hi,
and welcome to the forums !

Have you compared:
/usr/include/sys/pstat/pm_pstat_body.h
look for "define PST_UCOMMLEN"

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.

a_vinodkrishna
New Member

Re: pstat_getproc - Variation of string length of pst_ucomm

Hi Peter,
Thanks for the fast reply. I did check up on the pm_pstat_body.h header. In both the servers, it is defined in the same way:
#define PST_UCOMMLEN (14 + 1)
Any further pointers?

Cheers,
Vinod.
Laurent Menase
Honored Contributor
Solution

Re: pstat_getproc - Variation of string length of pst_ucomm

try
char commande[1024];
pstat(PSTAT_GETCOMMANDLINE,commande,
sizeof(commande),1,pid);

Best regards
Laurent Menase
a_vinodkrishna
New Member

Re: pstat_getproc - Variation of string length of pst_ucomm

Hi Laurent,
Thanks for the reply. This works perfectly on both my servers.
Could you pls throw some light on why it was not working the same way on server2 initially?
My concern is that we might have missed out applying some patches (?) on server2 which truncated the string length. Or is there any other work around / environment tweak which can be done without changing the existing code?
Cheers,
Vinod.
Laurent Menase
Honored Contributor

Re: pstat_getproc - Variation of string length of pst_ucomm

In fact the code would be

union pstun pst; pst.pst_command=&commande,
Status_i=pstat(PSTAT_GETCOMMANDLINE,
pst, sizeof(commande),1,pid);
# ./a.out
Proc Name : [a.out]
Proc Name : [./a.out]
# cp a.out 0123456789012345678901234567890
# ./0123456789012345678901234567890
Proc Name : [01234567890123]
Proc Name : [./0123456789012345678901234567890]
#

Cheers,
Laurent