系统相关
首页 > 系统相关> > c语言shmget shmctl共享内存操作

c语言shmget shmctl共享内存操作

作者:互联网

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


int main(int argc, char *argv[])
{
	int shmid;
	int ret;
	key_t key;
	char *shmadd;

	key =ftok(".",2012);
	if(key==-1)
	{
		perror("ftok");
	}
	system("ipcs -m");
	shmid=shmget(key,2048,SHM_R|SHM_W);
	if(shmid<0)
	{
		perror("shmat");
		exit(-1);
	}
	else
	{
	
		printf("delete shared-memory\n");
	}

	shmctl(shmid,IPC_RMID,NULL);
	system("ipcs -m");
	return 0;
}

标签:共享内存,shmget,int,char,ftok,key,shmctl,shmid,include
来源: https://blog.csdn.net/realmardrid/article/details/122579383