read.c
来自「进程间通信的实验代码」· C语言 代码 · 共 39 行
C
39 行
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <signal.h>#include <sys/msg.h>#include <sys/ipc.h>#include "message.h"#define SEGSIZE sizeof(struct mymsgbuf)main(){ struct mymsgbuf studentinfo; int shmid; key_t key; char *segptr; key=ftok(".",'S'); if((shmid = shmget(key, SEGSIZE, 0)) == -1) { perror("shmget not exist\n" ); exit(1); } /* Attach (map) the shared memory segment into the current process */ if((segptr = shmat(shmid, 0, 0)) == -1) { perror("shmat"); exit(1); } //read data from share memory. memcpy(&studentinfo,segptr,sizeof (struct mymsgbuf)); printf("you receive info:\n"); printf("\tid:\t %s\n",studentinfo.id); printf("\tname:\t %s\n",studentinfo.name); printf("\tage:\t %d\n",studentinfo.age); printf("\tE_mail:\t %s\n\n",studentinfo.e_mail); exit(0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?