LinuxQuestions.org
Visit Jeremy's Blog.
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 04-05-2012, 02:17 AM   #1
vdx
Member
 
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102

Rep: Reputation: 24
Unhappy how to get back existing msg queue id


I am using msgget() syscall to get new msg queue. I have used the IPC_CREAT & IPC_EXCL flags in that. like
Quote:
message_queue = msgget(ftok("/tmp", 100), (0666 | IPC_CREAT | IPC_EXCL));
Now, when my prog exists unexpectedly, the msg queue remains and I am failed to re-create the msg queue. So, my question is "How can I get back the existing msg queues's ID ?"

and by the way, where does msg queue stores its id ?
 
Old 04-05-2012, 03:22 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
How about
Code:
message_queue = msgget(ftok("/tmp", 100), 0666);
to get a handle back to the message queue?

The message queue details are stored in internal kernel structures. You can use msgctl(index,MSG_STAT,&info) to find information on all existing message queues. You need to scan with index starting from zero, increasing by one, until the call returns -1 with errno==EINVAL (for no more message queues). The key used for the msgget() call (ftok("/tmp",100)) is in info.msg_perm.__key.

You can use the ipcs -q command to list all message queues, and ipcrm -Q key or ipcrm -q id to delete a message queue.

This is all documented in the man 2 msgget and man 2 msgctl man pages.

Hope this helps,
 
1 members found this post helpful.
Old 04-05-2012, 03:31 AM   #3
vdx
Member
 
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102

Original Poster
Rep: Reputation: 24
thnx for the reply, Nominal Animal. It was very helpful
 
Old 04-05-2012, 02:30 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
man ipcrm for information on how to remove queues. They are intended to be persistent objects for rendezvous purposes.

Last edited by sundialsvcs; 04-05-2012 at 02:32 PM.
 
  


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
[SOLVED] adding existing distro back to boot loader robtreed Linux - Newbie 5 03-20-2011 09:52 PM
How to untar my tarred mail queue folder back to the sendmail queue directory again? Md.Abul Quashem Linux - Server 6 02-16-2010 08:32 AM
send to all that connect to same msg queue feetyouwell Programming 1 11-01-2004 12:41 PM
Semaphore, Msg queue with php? blackzone Programming 1 10-20-2004 01:06 AM

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

All times are GMT -5. The time now is 12:55 AM.

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