Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:27:56+00:00 2026-06-14T23:27:56+00:00

I would like to understand how message queues in Unix work. I wrote a

  • 0

I would like to understand how message queues in Unix work. I wrote a simple code which sends a short message to queue and then I can read that message. But my code shows :

enter image description here

And I dont know why – and I cant see a message I send to queue. Heres my code:

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

struct mymsgbuf {
    long mtype;
    char mtext[1024];
}msg;

int send_message(int qid, struct mymsgbuf *buffer )
{
    int result = -1, length = 0;
    length = sizeof(struct mymsgbuf) - sizeof(long);
    if((result = msgsnd(qid, buffer, length, 0)) == -1)
        return -1;
    return result;
}

int read_message(int qid, long type, struct mymsgbuf *buffer)
{
    int result, length;
    length = sizeof(struct mymsgbuf) - sizeof(long);
    if((result = msgrcv(qid, buffer, length, type,  0)) == -1)
        return -1;
    printf("Type: %ld Text: %s\n", buffer->mtype, buffer->mtext);
    return result;
}

int main(int argc, char **argv)
{
    int buffsize = 1024;

    int qid = msgget(ftok(".", 0), IPC_CREAT | O_EXCL);
    if (qid == -1)
    {
        perror("msgget");
        exit(1);
    }

    msg.mtype = 1;
    strcpy(msg.mtext, "my simple msg");

    if((send_message(qid, &msg)) == -1)
    {
        perror("msgsnd");
        exit(1);
    }

    if((read_message(qid, 1, &msg) == -1))
    {
        perror("msgrcv");
        exit(1);
    }

    return 0;
}

When I changed a line with msgget for this line:

int qid = msgget(ftok(".", 0), IPC_CREAT | O_EXCL | 0600);

it shows:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:27:57+00:00Added an answer on June 14, 2026 at 11:27 pm

    From the documentation for msgget:

    The low-order 9 bits of msg_perm.mode shall be set equal to the low-order 9 bits of msgflg.

    You need to add some permissions to your queue, at least read and write. Do something like:

    int qid = msgget(ftok(".", 0), IPC_CREAT | O_EXCL | 0600);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to understand how Etherpad's timeline feature work. If you don't know
I would like to understand what the following code is doing. This logic is
I have the warning message given in the title. I would like to understand
I would like to understand what Implement Interface Explicitly entails in C# based on
I would like to understand whats the best way to handle exceptions in Multicast
I would like to understand that what is Mesh Object and its conection with
I would like to understand what class << self stands for in the next
I would like to understand how object deletion works on python. Here is a
I am new to silver light and would like to understand a bit more
I am developing a Rails application and would like to understand when to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.