first commit

This commit is contained in:
2025-09-25 15:24:48 +09:00
parent 7a6918983f
commit a337ed6dd1

View File

@@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/mman.h>
int main(){
const int shmSize = 4096;
const char* shmName = "FOX";
const char* message_0 = "Hello, ";
const char* message_1 = "Shared Memory!\n";
int shm_fd; // Shared memory to file descripter
char* ptr; // Shared memory to pointer
shm_fd = shm_open(shmName, O_CREAT | O_RDWR, 0666);
ftruncate(shm_fd, shmSize);
ptr = (char*) mmap(0, shmSize, PROT_READ | PROT_WRITE, MAP_SHARED, shm_fd, 0);
sprintf(ptr, "%s", message_0);
ptr += strlen(message_0);
sprintf(ptr, "%s", message_1);
ptr += strlen(message_1);
return 0;
}