connect.c

来自「一个多进程通信的演示」· C语言 代码 · 共 47 行

C
47
字号
// copy#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/types.h>
#include <linux/sem.h>
#include <linux/shm.h>#include "connect.h"
int shmid;struct Pos{	int x;	int y;};struct Pos* pos;#define 	POS_ID		600int initConnect(){	shmid = shmget( POS_ID, sizeof( struct Pos ), IPC_CREAT|0666 );	if( shmid < 0 ){		printf("error");		return 0;		}			pos = (struct Pos*)shmat( shmid, NULL, SHM_R|SHM_W);		printf("proc1 connect init success!\n");	return 1;}void getPos( int *x, int *y ){	*x = pos->x;	*y = pos->y;}

⌨️ 快捷键说明

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