⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 share_memory.c

📁 linux编程的简单例子
💻 C
字号:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <stdlib.h>

#define BUFSZ 2048
int main()
{
	int shmid;
	char *shmadd;
	if((shmid=shmget(IPC_PRIVATE,BUFSZ,0666))<0){
		perror("shmget");
		exit(1);
	}
	else
		printf("created shared-memory: %d\n",shmid);
		system("ipcs -m");
	if((shmadd=shmat(shmid,0,0))<(char *)0){
		perror("shmat");
		exit(1);
	}
	else
		printf("attached shared-memory\n");
	system("ipcs -m");
	if((shmdt(shmadd))<0){
		perror("shmdt");
		exit(1);
	}
	else
		printf("deleted shared-memory\n");
	system("ipcs -m");
	exit(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -