linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve Graegert <graegerts@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: Detecting whether a Message Queue with a given qid exists?
Date: Mon, 31 Oct 2005 08:30:25 +0100	[thread overview]
Message-ID: <6a00c8d50510302330m193cdc91v93b745be3b2f456f@mail.gmail.com> (raw)
In-Reply-To: <b115cb5f0510302311ma397fb1k65ec88a605f33adf@mail.gmail.com>

On 10/31/05, Rajat Jain <rajat.noida.india@gmail.com> wrote:
> Hi,
>
> This is the reagrding the message queue mecahnism of sys V IPC.
>
> Is there a way to find out that whether a message queue with a
> particular qid exists?

msgget returns a valid queue identifier.  To see if the queue still
exists when you try to place a message into the queue via msgsend,
check for EINVAL, which is returned if the queue identifier is not
valid (any more):

int result, msqid;

struct m {
	long type;
	char text[64];
} msg;

m.type = 1;
strcpy(m.text, "Hi, I am a message");

if ((queue_id = msgget(KEY, 0666)) == -1) {
	/* handle error */
}
... /* do some stuff here */
result = msgsnd(queue_id, (void *)&m, sizeof(m.text), IPC_NOWAIT);
... /* check error here */
	
Hope this helps.



	\Steve

  reply	other threads:[~2005-10-31  7:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-31  7:11 Detecting whether a Message Queue with a given qid exists? Rajat Jain
2005-10-31  7:30 ` Steve Graegert [this message]
2005-11-01  6:22   ` Rajat Jain
2005-11-01  9:11     ` Steve Graegert
2005-11-02  3:00       ` Rajat Jain
  -- strict thread matches above, loose matches on Subject: below --
2005-10-31  7:15 JOSEPH ALPHONSE

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a00c8d50510302330m193cdc91v93b745be3b2f456f@mail.gmail.com \
    --to=graegerts@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).