LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-02-2009, 06:45 AM   #1
aryan1
Member
 
Registered: Jul 2009
Posts: 50

Rep: Reputation: 16
Question problem with msgrcv() when executed for a second time


Hi Again,

I use message queues to communicate data between two processes, namely, A and B.

A basically sends a message to B using msgsnd() as follows (the standard steps):

struct myMsg
{
long int mtype;
char mtext[1500];
} myBuf;

// Set the fields in myBuf here ...
myBuf.mtype = 1;
...

// Create the message queue if it does not exist
mqId = msgget(mqKey, IPC_CREAT | IPC_EXCL | 0660 );

// buf is struct msqid_ds, mqKey is set using ftok()
buf.qbytes = 200000; // size of the message queue
...

// resize the message queue to a non-default one
msgctl(mqId, IPC_SET, buf);

while(1)
{
msgsnd(mqId, &myBuf, sizeof(struct myMsg), 0);
}

***********************************************

B receives the messages the following way (the standard steps):

struct myMsg
{
long int mtype;
char mtext[1500];
} myBuf;

// mqKey is the same as the one returned by ftok() in A process
// Open the message queue if it exists
mqId = msgget(mqKey, IPC_CREAT | 0660 );

while(1)
{
msgrcv(mqId, &myBuf, sizeof(struct myMsg), 1, MSG_NOERROR);
}

*************************************************

A is always started before B.

When I first run A and B after booting the system, they work fine -- I can observe it.

However, after I stop them and "ipcrm" the message queue without rebooting the system, if I start them again, A works fine, however, msgrcv() in B crashes even without returning -1. (I can verify that the execution reaches the msgrcv() by checking the application logs)

Any idea ? If I missed any information required, please feel free to ask.

Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with msgrcv qnomans2k Red Hat 0 02-06-2009 02:06 AM
time when a command was executed. anandkj Linux - Newbie 3 12-21-2007 01:09 AM
rc.local isn't executed at boot time elvijs Slackware 3 06-24-2007 06:48 AM
Commands executed at boot time Johnburrell Linux From Scratch 3 09-18-2005 01:56 PM
msgrcv problem chiahsin Linux - Software 0 12-02-2004 03:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration