linux 进程间的通讯之共享内存 读取篇

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>


int main()
{
int shmId;
char* shmaddr;
key_t key;

key=ftok(".",1);

// int shmget(key_t key, size_t size, int shmflg);
shmId=shmget(key,1024*4,0);//找到内存空间

if(shmId==-1){
printf("memo get fail\n");
}

// void *shmat(int shmid, const void *shmaddr, int shmflg);
shmaddr=shmat(shmId,0,0);//内存的映射

printf("data:%s\n",shmaddr);//输出内存的内容

shmdt(shmaddr);//关闭映射

printf("quit\n");


return 0;
}

linux 进程间的通讯之共享内存 读取篇

上一篇:Status code :200 OK (from disk cache)


下一篇:shell operator EOF shell 操作符