Deleting ALL message queue

hi all,
I'm working on this problem for 2 days. Can somebody tell me that how to delete all message queues from the system ?
Since "ipcs -q" gives the list of all existing message queue, then there must be a system call and data stucture where from I can fetch the data about all existing message queues.
I just want to know, how i can delete ALL message queues from the system thruogh a C program.

The best way to get a systemwide list of the message queues is via popen("ipcs -q", "r") but that's not what you want to hear. Programs like ps, sar, vmstat, etc cannot be portably written. You must not realize this, or you would have broken with tradition and mentioned your specific OS as you posed the question.

With standard System V release 4, you would run namelist(3) on the kernel to obtain the address of msginfo. You would then open(2) /dev/kmem, lseek(2), to that address, and read(2) the data structure. You would know the the layout of the data structure because it is somewhere in /usr/include/sys.

This exact sequence of operations is not likely to work on modern OS's, even those based on System V, release 4. Some vendors do not want to support stuff like this and worked hard to render it impossible with a little bit of success. Others have fiddled greatly with the OS and different techniques must now be employed. In general, you need to obtain the source code for your OS, view ipcs.c and copy what it does.

Sir,thank you for your valuable suggestion. I'll surely try this thing out and tell you the results.
You wrote that i need to obtain the source code for my OS in order to know how "ipcs.c" works. Can you tell me how i can get the source code of my OS?? i'm using Red Hat 9.
One more request, can i add you in my buddy list??