在cygwin上运行共享内存程序



我试图在Windows中的cygwin上运行以下代码;其中不会有编译错误,但是当我尝试运行它时,我遇到了错误的系统调用(核心转储)错误。

 #include <sys/types.h>
 #include <sys/ipc.h> 
 #include <sys/shm.h> 
 #include <stdio.h> 
 #include <stdlib.h>
 void main ( ) 
 { int shm_id; key_t mem_key;
 int *shm_ptr; 
 mem_key = ftok(".", 'a'); 
 shm_id = shmget(mem_key, sizeof(int), IPC_CREAT | 0666);
 if (shm_id < 0) 
 { printf("*** shmget error (server) ***n");
 exit(1);
 }
 shm_ptr = (int *) shmat(shm_id, NULL, 0); 
 /* attach */ 
 if ((int) shm_ptr == -1) 
 {
 printf("*** shmat error (server) ***n");
 exit(1);
 } 
}

为什么我有这个错误?我可以解决吗?

多谢。

您需要配置并启动 cygserver。

最新更新