[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Message Q error

Posted on 2004-09-28
7
Medium Priority
?
193 Views
Last Modified: 2010-04-21
working on message Q with a parent and child process and the Q is not being created, getting an Error # 38 on it.  This is the program:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/msg.h>
#include <sys/ipc.h>
#include <errno.h>


struct myMessage
      {
            long int message_type;
            char some_text[3];
      };
      
int main()
{
      int messageQ;
      pid_t processNum= fork();            
      
      // create messageQ
      
      if(processNum==0)
      {   printf("child: create and send messQ, process=0 ");
            messageQ=getmsg((key_t)1234, 0666|IPC_CREAT);
            fprintf(stderr,"messageerror: %d\n",errno);
            printf("creatQ = %d ",messageQ);
            //create message
      
            struct myMessage message;
            message.message_type=0;
            message.some_text[0]='1';
            message.some_text[1]='2';
            message.some_text[2]='3';
      
            //send message
            msgsnd(messageQ,(void *)&message,3,0);
            printf("MSG sent ");
            printf("sentQ = %d ",messageQ);
      
      }
      
      if(processNum!=0)
      {      printf("Waiting ");
            printf("%d ",processNum);
            wait(10);
      }

      
      
      // create struct pointer to return results into
      int success = 0;
      if(processNum!=0)
      {      struct myMessage recievedMsg;
            success=msgrcv(messageQ, (void *)&recievedMsg,3, 0 ,0);
            printf("recQ = %d ",messageQ);
              printf("success: %d",success);

      }
      

      
      return 0;
      
}


0
Comment
Question by:johnduff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 11

Accepted Solution

by:
cjjclifford earned 800 total points
ID: 12171297
I would guess that the messageQ would have to be created before the fork(), or at least the line:

messageQ=getmsg((key_t)1234, 0666|IPC_CREAT);

should be also in the parent block, before the msgrcv() call...

Also, the child and parent code blocks shouldn't flow into each other... currently, the child code runs straight into the parent logic - put in an else { } for the parent logic, rather than continually checking if this is the parent, just do it once...

what's happening now is the variable messageQ is only getting assigned to in the child, so the parent doesn't have a Q to connect to...
0
 
LVL 2

Author Comment

by:johnduff
ID: 12172245
when the getmsg() is called for the first time the messeageQ that is returned is -1, which I'm taking it to mean that the messageQ is not being created at all.  Tried moving that line before the fork and the only thing it fixes is that when the parent calls msgrcv() it's getting -1 returned as well, before it was getting a random int value.
0
 
LVL 2

Author Comment

by:johnduff
ID: 12172647
Tried to do just the msgget to create the message Q and it dosn't do anyhting, returns -1, please help if you can
0
 
LVL 2

Author Comment

by:johnduff
ID: 12173831
okay, i created a new file and just did the msgget() and for some reason now when i create a messageQ it returns 0 instead of -1, which means it was created.  so this is solved for now, i will post to this again if i come across a real problem and not just the computer being stupid.

John
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 12419170
From the author's first comment it looks like my answer did help a bit....
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question