Unix Programming - Removal of all the message queues in system

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > April 2004 > Removal of all the message queues in system





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Removal of all the message queues in system
Ash

2004-04-18, 10:42 am

Is it possible to write a C program that could remove ALL the message
queues in the system?
Michael Kerrisk

2004-04-19, 2:34 am

On 17 Apr 2004 02:09:58 -0700, amujoo@yahoo.com (Ash) wrote:

>Is it possible to write a C program that could remove ALL the message
>queues in the system?


Yes. There are non-portable implementation specific methods (what
implementation are you using), or alternatively you can parse the
output of ipcs(1).

Cheers,

Michael
Ash

2004-04-20, 2:36 pm

can you please give me a piece of C code to perform removal of all
message queues. i am not able to think of anything. i dont think
parsing ipcs output is a good idea.

Michael Kerrisk <michael.kerrisk.at.gmx.net@nospam.com> wrote in message news:<3lr680tpk2c50ba50sai2jllf3ocu8k2l9@4ax.com>...
> On 17 Apr 2004 02:09:58 -0700, amujoo@yahoo.com (Ash) wrote:
>
>
> Yes. There are non-portable implementation specific methods (what
> implementation are you using), or alternatively you can parse the
> output of ipcs(1).
>
> Cheers,
>
> Michael

Dragan Cvetkovic

2004-04-20, 2:36 pm

amujoo@yahoo.com (Ash) writes:

> Michael Kerrisk <michael.kerrisk.at.gmx.net@nospam.com> wrote in message news:<3lr680tpk2c50ba50sai2jllf3ocu8k2l9@4ax.com>...
[vbcol=seagreen]
> can you please give me a piece of C code to perform removal of all
> message queues. i am not able to think of anything. i dont think
> parsing ipcs output is a good idea.
>


Well, it depends on the OS. On Solaris for example you can use msgids(2) to
get the list of message queue identifiers and then use msgctl(2) to remove
them one by one.

HTH, Dragan


--
Dragan Cvetkovic,

To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!
Michael Kerrisk

2004-04-21, 2:34 am

On 20 Apr 2004 10:50:32 -0700, amujoo@yahoo.com (Ash) wrote:

>can you please give me a piece of C code to perform removal of all
>message queues. i am not able to think of anything. i dont think
>parsing ipcs output is a good idea.


Ahh, no I can't -- first of all because you didn't answer the
question: what implementation are you using?

Cheers,

Michael[vbcol=seagreen]
>
>Michael Kerrisk <michael.kerrisk.at.gmx.net@nospam.com> wrote in message news:<3lr680tpk2c50ba50sai2jllf3ocu8k2l9@4ax.com>...

Ash

2004-04-21, 2:34 am

Dragan Cvetkovic <me@privacy.net> wrote in message news:<lm4qrejyqz.fsf@privacy.net>...
> amujoo@yahoo.com (Ash) writes:
>
>
>
> Well, it depends on the OS. On Solaris for example you can use msgids(2) to
> get the list of message queue identifiers and then use msgctl(2) to remove
> them one by one.
>
> HTH, Dragan



But even msgids is not present in Sol 8. On Red Hat linux there isnt
any such syscall. So how would it be possible on linux? Any clues?
Dragan Cvetkovic

2004-04-21, 7:35 am

amujoo@yahoo.com (Ash) writes:

> Dragan Cvetkovic <me@privacy.net> wrote in message news:<lm4qrejyqz.fsf@privacy.net>...
[vbcol=seagreen]
>
> But even msgids is not present in Sol 8. On Red Hat linux there isnt
> any such syscall. So how would it be possible on linux? Any clues?


Strange. msgids(2) is available on Solaris 8 systems I have access to. What
revision of it you have? I have no ideas about Linux though.

Bye, Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!
Michael Kerrisk

2004-04-22, 3:36 am

On Wed, 21 Apr 2004 07:30:57 -0400, Dragan Cvetkovic <me@privacy.net>
wrote:

>amujoo@yahoo.com (Ash) writes:
>
>
>
>Strange. msgids(2) is available on Solaris 8 systems I have access to. What
>revision of it you have? I have no ideas about Linux though.


(It's also available on the Solaris 8 systems that I can access.)

The OP seems intent on not listening to advice or answering
questions ;-) : parsing the output of ipcs is *the* most portable way
of solving this problem.

It appears from the above post that the OP is interested primarily in
Solaris and Linux. Dragan has posted the Solaris-specific alternative
to parsing ipcs output.

On Linux, there are two different ways of solving this problem:

-- read the contents of /proc/sysvipc/msg (Linux 2.4 and later)

-- make use of the IPC_INFO and MSG_STAT msgctl() operations

Both of the above methods are *not* portable. The second of these
techniques is shown below.

Cheers,

Michael



/* List all System V message queues */

#define _GNU_SOURCE
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

#define errMsg(msg) { perror(msg); }

#define errExit(msg) { perror(msg); exit(EXIT_FAILURE); }

int
main(int argc, char *argv[])
{
int maxind, ind, msqid;
struct msqid_ds ds;
struct msginfo msginfo;

/* Obtain size of kernel 'entries' array */

maxind = msgctl(0, IPC_INFO, (struct msqid_ds *) &msginfo);
if (maxind == -1) errExit("msgctl");

printf("maxind: %d\n\n", maxind);
printf("index id key messages\n");

for (ind = 0; ind <= maxind; ind++) {
msqid = msgctl(ind, MSG_STAT, &ds);
if (msqid == -1) {
if (errno != EINVAL && errno != EACCES)
errMsg("msgctl-MSG_STAT"); /* Unexpected error */
continue; /* Ignore this item */
}

printf("%4d %8d 0x%08x %7ld\n", ind, msqid,
ds.msg_perm.__key, (long) ds.msg_qnum);
}

exit(EXIT_SUCCESS);
} /* main */
Ash

2004-04-22, 4:34 am

Michael Kerrisk <michael.kerrisk.at.gmx.net@nospam.com> wrote in message news:<gn2c80tl32hjuqap6gmantj5uv1m9btd38@4ax.com>...[vbcol=seagreen]
> On 20 Apr 2004 10:50:32 -0700, amujoo@yahoo.com (Ash) wrote:
>
>
> Ahh, no I can't -- first of all because you didn't answer the
> question: what implementation are you using?
>
> Cheers,
>
> Michael

I have access to Sol 8 machine, in which I tried man msgids. and it
says man page not found. Then I want to get this thing done on Linux
where no such thing could found. I would need a C code.

Thanks
ash
Casper H.S. Dik

2004-04-22, 5:34 am

amujoo@yahoo.com (Ash) writes:

>I have access to Sol 8 machine, in which I tried man msgids. and it
>says man page not found. Then I want to get this thing done on Linux
>where no such thing could found. I would need a C code.


The Solaris 8 system I tried it on does have the msgids/shmids/semids
manual pages. You can also check docs.sun.com for the specific manual
pages.

Older releases did go throught the trouble of reading /dev/kmem.

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Dragan Cvetkovic

2004-04-22, 9:37 am

Casper H.S. Dik <Casper.Dik@Sun.COM> writes:

> amujoo@yahoo.com (Ash) writes:
>
>
> The Solaris 8 system I tried it on does have the msgids/shmids/semids
> manual pages. You can also check docs.sun.com for the specific manual
> pages.
>


And the earliest Solaris 8 machine that we have has the following header in
/usr/share/man/man2/msgids.2:

<!-- @(#)msgids.2 1.1 00/03/08 SMI; -->

That is on a Solaris 8 10/00 release. When was Solaris 8 FCS?

Bye, Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole No it isn't. L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!
Casper H.S. Dik

2004-04-22, 12:36 pm

Dragan Cvetkovic <me@privacy.net> writes:

>And the earliest Solaris 8 machine that we have has the following header in
>/usr/share/man/man2/msgids.2:


> <!-- @(#)msgids.2 1.1 00/03/08 SMI; -->


>That is on a Solaris 8 10/00 release. When was Solaris 8 FCS?



Early 2000, I think (last S7 was 11/99; first S8 update was
06/00)

Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
Ash

2004-04-23, 12:33 am

amujoo@yahoo.com (Ash) wrote in message news:<60aab6b4.0404170109.767b2070@posting.google.com>...
> Is it possible to write a C program that could remove ALL the message
> queues in the system?


Anyway so we can conclude that it removal of msg qeuees by a C program
is not possible on LINUX? right? none responded for linux here.
Michael Kerrisk

2004-04-23, 2:34 am

On 22 Apr 2004 21:38:55 -0700, amujoo@yahoo.com (Ash) wrote:

>amujoo@yahoo.com (Ash) wrote in message news:<60aab6b4.0404170109.767b2070@posting.google.com>...
>
>Anyway so we can conclude that it removal of msg qeuees by a C program
>is not possible on LINUX? right? none responded for linux here.


Are you paying attention? Have you read all my posts in this thread?
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com