lkml.org 
[lkml]   [2001]   [Jul]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjecthow kernel handles sharedmemory
hi
I am surprised how kernel handles the shared memory. When I
give issues shmget command, a sharedmemory is created and id is returned. then
I can use that sharememory by assigning to a charector array.
Now in my situation, presently there is a two
dimensional array. I want to put the whole array in the shared memory. This is
because I need to share this array between the processes. So what I done is ,
I created a linklistin sharememory. But it is not working. I am giving a
sample program. Will anyone can

#include <sys/shm.h>
typedef struct Alligned
{
int count1;
int count2;
int count3;
}Alligned_pair;

char* share_alloc(int size);
Alligned_pair **m_alligned_pair;

int main()
{
int shmid,count,childpids[1000],pid;
Alligned_pair *s,**q;
m_alligned_pair=(Alligned_pair**)share_alloc(1000*sizeof(Alligned_pair*));


for(count=0;count<10;count++)
{
pid=fork();

if (pid==0)
{
s=(Alligned_pair*)share_alloc(sizeof(Alligned_pair));
s->count1=count;
m_alligned_pair[count]=s;
pid=getppid();
waitpid(pid,0,0);
exit(0);
}


else
{
childpids[count]=pid;
}
}
sleep(2);
for(count = 0; count<20; count++)
{
printf("%d %d\n",m_alligned_pair[count],
m_alligned_pair[count]->count1);
}
return 1;
}


char* share_alloc(int size)
{
int shmid;
char *SArray;
shmid=shmget(random(),size,IPC_CREAT|777);
SArray=shmat(shmid,0,0);
return SArray;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:56    [W:0.029 / U:0.468 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site