newlist

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

#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;
}

posted on 2011-11-24 14:27  一枚程序  阅读(149)  评论(0编辑  收藏  举报