Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interprocess Communication

Status
Not open for further replies.

lk5990

Programmer
Jul 2, 2001
7
US
I'm trying to use mq_notify for a real time application to prevent the users from getting 'hung up' waiting for a response from a queue. In my code I have created mqueue_1 and send out a request to another queue, which should return a response to mqueue_1. The code then calls mq_notify before calling mq_receive for mqueue_1. I have tested killing the executable with the second queue in hopes that mq_notify will return an error since mqueue_1 should be empty. Mq_notify returns 0 and I get stuck in mq_receive. Here's my code

mqd_t md, mqueue_1;
struct mq_attr attr;
struct sigevent sigev;

attr.mq_maxmsg = 200;
attr.mq_msgsize = MSGSIZE;
attr.mq_flags = 0;
me = mq_open(qname, O_CREAT|O_RDWR, PMODE, &attr);
if (me == (mqd_t)-1)
perror("Couldn't open my message queue");
...
sprintf(message, "%s|%s|MA|WOBURN|%s||", qname, zipc, addr);
md = mq_open("/verifyaddrb", O_RDWR);
status = mq_send(md, message, strlen(message), 1);

status = mq_notify(mqueue_1, &sigev);/* status return 0 even if nothing is there */
mq_rec = mq_receive(mqueue_1, message2, MSGSIZE, 0); /* hung up here if /verifyaddrb was killed */

Also if you know of any good documentations on POSIX threads I would really appreciate it.
Thanks
 
lk5990,

mq_motify is used to set up a signal which will be sent when something is placed on the queue. The read then is handled in the signal handler.

Also, a POSIX message queue has kernel persistence, meaning that it will persist if all processes detach from it. You cannot detect if a process which is supposed to communicate with queue has exited with the queue alone.

The way that I have handled this is to trap all of the errant signals (SIGFPE, SIGSEGV, SIGBUS, etc) and either send a message to the queue and then exit or remove the queue then exit. In either case mq_receive will return and the process will not hang.

W. Richard Stevens, UNIX Network Programming Vol. 2 is highly recommended.

Brudnakm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top