first commit
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user