#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/