1825191 Members
4228 Online
109679 Solutions
New Discussion юеВ

msgrcv issue

 
SOLVED
Go to solution
Michal Rokos
Occasional Advisor

msgrcv issue

Hello,

I've noticed following issue: having two or more processes that receive IPC messages via msgrcv() call are getting stuck when one process requesting msgtyp > 0 and other one(s) have msgtyp = 0.

Have you noticed something like this?

> uname -mnrsv
HP-UX ktest B.11.31 U ia64
> model
ia64 hp server rx7640
9 REPLIES 9
Michal Rokos
Occasional Advisor

Re: msgrcv issue

Attaching example: when sending message (via msg_s) on 15:54:48 and 15:55:00, messages are delivered to msg_r process on 15:55:00. So the process msg_r (with mtype=0) had been sleeping and was not woke up by OS on 15:54:48.

# ./msg_r
creating msgq...
Mon Apr 12 15:54:40 2010
msgq_id = 20971608, mtype = 999

# ./msg_r 20971608
reusing msgq [20971608]
Mon Apr 12 15:54:45 2010
msgq_id = 20971608, mtype = 0
Mon Apr 12 15:55:00 2010
received 1 [Hello]
Mon Apr 12 15:55:00 2010
msgq_id = 20971608, mtype = 0
Mon Apr 12 15:55:00 2010
received 1 [Hello]
Mon Apr 12 15:55:00 2010
msgq_id = 20971608, mtype = 0

# ./msg_s 20971608 1 'Hello'
Mon Apr 12 15:54:48 2010
msgq_id = 20971608, mtype = 1, mtext [Hello]
# ./msg_s 20971608 1 'Hello'
Mon Apr 12 15:55:00 2010
msgq_id = 20971608, mtype = 1, mtext [Hello]
Michal Rokos
Occasional Advisor

Re: msgrcv issue

> cat msg_r.c
#include
#include
#include
#include

typedef struct
{
long mtype;
char mtext[100];
} msgx_ent;

int main( int argc, char *argv[] )
{
int msgq_id;
time_t t;
msgx_ent msgx_buf;
int msg_len;

setvbuf(stdout, NULL, _IONBF, 0);

if ( argc > 1 )
{
printf("reusing msgq [%s]\n", argv[1]);
msgq_id = atoi(argv[1]);
}
else
{
printf("creating msgq...\n");
msgq_id = msgget(IPC_PRIVATE, 0664);
}

again:
t = time(NULL);
printf("%s\tmsgq_id = %d, mtype = %d\n",
ctime(&t), msgq_id, argc > 1 ? 0 : 999);

msg_len = msgrcv(msgq_id, &msgx_buf, 100, argc > 1 ? 0 : 999, 0);

t = time(NULL);
if ( msg_len < 0 )
{
printf("%s\tmsg_len = %d, errno = %d\n",
ctime(&t), msg_len, errno);
}
else
{
printf("%s\treceived %d [%s]\n",
ctime(&t), msgx_buf.mtype, msgx_buf.mtext);
}
goto again;

return 0;
}
Michal Rokos
Occasional Advisor

Re: msgrcv issue

> cat msg_s.c
#include
#include
#include
#include

typedef struct
{
long mtype;
char mtext[100];
} msgx_ent;

int main( int argc, char *argv[] )
{
int msgq_id;
time_t t;
msgx_ent msgx_buf;
int msg_len;

setvbuf(stdout, NULL, _IONBF, 0);

msgq_id = atoi(argv[1]);
msgx_buf.mtype = atoi(argv[2]);
strcpy(msgx_buf.mtext, argv[3]);

t = time(NULL);
printf("%s\tmsgq_id = %d, mtype = %ld, mtext [%s]\n",
ctime(&t), msgq_id, msgx_buf.mtype, msgx_buf.mtext);

msg_len = msgsnd(msgq_id, &msgx_buf, strlen(msgx_buf.mtext)+1, 0);

if ( msg_len < 0 )
{
printf("msg_len = %d, errno = %d\n", msg_len, errno);
}

return 0;
}
Michal Rokos
Occasional Advisor

Re: msgrcv issue

More investigation:
- issue persist on ELF-64 and ELF-32 binaries
- issue vanish when I send message with msgtype == 999 (the one that is specified in msgrcv() call)

Any idea what's wrong?
James R. Ferguson
Acclaimed Contributor

Re: msgrcv issue

Hi:

You might use 'tusc' to see some details. You don't offer any code, in particular the setting of 'msgflg' and any values of 'errno'.

Regards!

...JRF...
James R. Ferguson
Acclaimed Contributor
Solution

Re: msgrcv issue

Hi (again):

You might look at patch PHKL_40306 or its successor PHKL_40367.

Regards!

...JRF...
Michal Rokos
Occasional Advisor

Re: msgrcv issue

Thank you for your help.
Indeed, this patch is not applied. I've just asked admin for installation. In case it solves the issue (or not), I will update the status here.

Thank you! Michal
Michal Rokos
Occasional Advisor

Re: msgrcv issue

I can confirm that patch, you've suggested, fixed the issue we had. Thank you very much for your help. Michal
James R. Ferguson
Acclaimed Contributor

Re: msgrcv issue

Hi (again):

> I can confirm that patch, you've suggested, fixed the issue we had. Thank you very much for your help. Michal

If you are happy with the answers you received, please read this about assigning points:

http://forums13.itrc.hp.com/service/forums/helptips.do?#28

Regards!

...JRF...