Cygwin环境下共享内存 Shmget()调用失败 Bad System Call
在Cygwin 环境下如下代码。调用到 shmid = shmget(key,SHM_SIZE,IPC_CREAT)时 提示 Bad System Call
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define ARRAY_SIZE 40
#define MALLOC_SIZE 1024
#define SHM_SIZE 1024
#define SHM_MODE (SHM_R | SHM_W)
char array[ARRAY_SIZE];
int main(void){
int shmid;
char *ptr,*shmptr;
key_t key;
key = ftok(".",'1');
if((ptr = malloc(MALLOC_SIZE)) == NULL)
printf("malloc error!");
printf("maloc ok!");
if((shmid = shmget(key,SHM_SIZE,IPC_CREAT)) < 0 )
printf("shmget error!!!");
if((shmptr = shmat(shmid,0,0)) == (void *)-1)
printf("shmat error!");
if (shmctl(shmid,IPC_RMID,0) < 0)
printf("shmctl error!");
exit(0);
}