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 9084739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:04:17+00:00 2026-06-16T21:04:17+00:00

gcc 4.72 c89 I am using this book as a reference to do mq_*

  • 0
gcc 4.72 c89

I am using this book as a reference to do mq_* posix message queues.

The Linux Programming Interface by Michael Kerrisk page 1071

However, in this example snippet I have noticed that they open a message queue get some attributes from the queue. However, they have failed to close it.

Isn’t this bad practice as a resource leak could occur as all message queue descriptors could be used up if they are not returned to the OS? I guess when the process dies if would automatically return all resources back to the OS. However, if a process is running on a server 24/7 then this could have a major impact.

Many thanks for any suggestions,

int main(int argc, char *argv[])
{
    mqd_t mqd;
    struct mq_attr attr;
    if (argc != 2 || strcmp(argv[1], "--help") == 0)
        usageErr("%s mq-name\n", argv[0]);

    mqd = mq_open(argv[1], O_RDONLY);
    if (mqd == (mqd_t) -1)
        errExit("mq_open");

    if (mq_getattr(mqd, &attr) == -1)
        errExit("mq_getattr");

    printf("Maximum # of messages on queue: %ld\n", attr.mq_maxmsg);
    printf("Maximum message size: %ld\n", attr.mq_msgsize);
    printf("# of messages currently on queue: %ld\n", attr.mq_curmsgs);

    exit(EXIT_SUCCESS);
}
  • 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-16T21:04:19+00:00Added an answer on June 16, 2026 at 9:04 pm

    Yes, it is a bad practice.
    But all the resources given to a process are reclaimed by the OS once the process exits.
    In this case the resource only leaks for an insignificant amount of time,
    between end of usage of queue and end of program, which is significantly small and hence immaterial.

    In case of a continuously running process, you must clean all resources acquired explicitly or it results in a resource leak.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

gcc 4.7.2 c89 Hello, I am using posix message queues: mq_create, mq_send, mq_receive, etc.
I'm using gcc 4.7.0, in c89 mode. I have this if-else statement and have
gcc 4.4.3 c89 linux I am using log4c and have placed the inc and
gcc (GCC) 4.6.3 c89 Hello, I am just wondering if this is the best
gcc 4.4.4 c89 I am using the code below. However, I keep getting the
gcc 4.7.2 c89 Hello, I am using the APR safe thread queue in the
gcc 4.6.2 c89 I am just wondering if this is a good way to
gcc 4.7.2 c89 Hello, I am using the Apache Portable Runtime and looking at
gcc 4.5.1 c89 I am using the following code to read in a line
gcc 4.7.2 c89 APR 1.4 Hello, I am using APR thread pools, event loop

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.