#include "public.h"
int main()
{
mem_no=shmget(MEM_KEY,10*MEM_SIZE,MEM_FLAG);
pstudent=(StuNodes)shmat(mem_no,NULL,0);
pstudent_first=pstudent;
pstudent_first2=pstudent;
//读取数据
for (int i=0;i<10;i++)
{
printf("student.no=%d student.username=%s\n",pstudent_first->no,pstudent_first->username);
pstudent_first++;
sleep(1);
}
//卸载共享内存
if (shmdt(pstudent_first2)==-1)
{
printf("fail to dattach share memory \n");
}
printf("press any key to remove share memory ... \n");
getchar();
if (shmctl(mem_no,IPC_RMID,0)==-1)
{
printf("fail to IPC_RMID\n");
}
return 0;
}