diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 4d8865ff..c7fac128 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -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) diff --git a/apps/shmem-test.cpp b/apps/shmem-test.cpp new file mode 100644 index 00000000..c9c31f65 --- /dev/null +++ b/apps/shmem-test.cpp @@ -0,0 +1,35 @@ +#include +#include +#include +#include + +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; +}