qfedu-linux-advanced-level/day5/shm1.c

30 lines
1.3 KiB
C
Raw Normal View History

2023-08-18 16:47:04 +08:00
// 共享内存
/*
"shm"shared memory
Linux系统中使`shmget`shared memory segment
"shm""share mem"使
*/
#include <sys/shm.h>
#include <stdio.h>
#include <sys/types.h>
int main()
{
key_t key = ftok("/", 28);
// 获取共享内存的标识
int shmid = shmget(key, 32, IPC_CREAT | 0666);
if (shmid == -1)
{
perror("shmget");
return 1;
}
printf("shmid=%d\n", shmid);
return 0;
}