mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 18:26:48 +00:00
* 实现SystemV共享内存 * 测试shm * 添加测试程序 * 完善细节 * 修正shm的时间数据错误的问题 * fix: devfs的metadata权限为0x777的错误 --------- Co-authored-by: longjin <longjin@DragonOS.org>
40 lines
702 B
C
40 lines
702 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/shm.h>
|
|
#include <sys/ipc.h>
|
|
#include <string.h>
|
|
#include <sys/wait.h>
|
|
|
|
#define SHM_SIZE 9999
|
|
|
|
int main()
|
|
{
|
|
int shmid;
|
|
char *shmaddr;
|
|
key_t key = 6666;
|
|
|
|
// 测试shmget
|
|
shmid = shmget(key, SHM_SIZE, 0666 | IPC_CREAT);
|
|
if (shmid < 0)
|
|
{
|
|
perror("shmget failed");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
// 测试shmat
|
|
shmaddr = shmat(shmid, 0, 0);
|
|
|
|
char read_buf[20];
|
|
memcpy(read_buf, shmaddr, 14);
|
|
|
|
printf("Receiver receive: %s\n", read_buf);
|
|
|
|
memset(shmaddr, 0, SHM_SIZE);
|
|
memcpy(shmaddr, "Reveiver Hello!", 16);
|
|
|
|
shmdt(shmaddr);
|
|
|
|
return 0;
|
|
} |