Listing Shared Memory Segments in C
February 11, 2009
In this week I had to write a little code to remove all IPC Shared Memory segments that were created by one process.
I had already done it on Linux and *BSD systems, but never on (Open)Solaris. Then, I tried to search (googling) some method to do it but without successful.
Linux and *BSD’s have a syscall named sysctl() to interface it, but sunos kernel has not.
Well, after some minutes breaking my brain, I discover a syscall easiest to use than sysctl…look the code below:
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
void show_shm (void)
{
int i;
int *buf;
uint_t nids;
uint_t pnids;
for (;;)
{
if (shmids(buf, nids, &pnids) != 0)
exit(1);
if (pnids <= nids)
break;
buf = realloc(buf, (nids = pnids) * sizeof (int));
}
for (i = 0; i < pnids; i++)
printf ("%dn", buf[i]);
}

Posted by richizo
Filed in OpenSolaris
Tags: C, ipc, kernel, listing shared memory segments on Solaris, OpenSolaris, shared memory, shared memory on solaris
1 Comment » Filed in OpenSolaris
Tags: C, ipc, kernel, listing shared memory segments on Solaris, OpenSolaris, shared memory, shared memory on solaris








February 13, 2009 at 9:14 pm
Ta ficando bom em opensolaris hein =p