apps: Add shmem-test
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-08-02 22:19:47 +02:00
parent f66b0497cf
commit 7293d47bf0
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 36 additions and 0 deletions

View File

@ -45,3 +45,4 @@ luna_app(buffer-test.cpp buffer-test)
luna_app(socket-test.cpp socket-test)
luna_app(socket-client.cpp socket-client)
luna_app(input.cpp input)
luna_app(shmem-test.cpp shmem-test)

35
apps/shmem-test.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
int main()
{
void* address = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, -1, 0);
if (address == MAP_FAILED)
{
perror("mmap");
return 1;
}
int* ptr = (int*)address;
*ptr = 16;
pid_t child = fork();
if (child < 0)
{
perror("fork");
return 1;
}
if (child == 0)
{
*ptr = 32;
_exit(0);
}
waitpid(child, NULL, 0);
printf("the value is %d\n", *ptr);
return 0;
}