diff options
| author | auric <104602845+ihateamongus@users.noreply.github.com> | 2025-09-08 21:19:14 -0500 |
|---|---|---|
| committer | auric <104602845+ihateamongus@users.noreply.github.com> | 2025-09-08 21:19:14 -0500 |
| commit | e61da07522a060da98fa3a56db3d0360469b26cf (patch) | |
| tree | c72d276bffa4dafe22ae0e4f694acfadb40b8ca1 /archive/breathing-exo-daemon/display/display-shm.c | |
| parent | d11aec86841f77edd6eba3e07aa1e7e591e9da2a (diff) | |
organize repository layout
Diffstat (limited to 'archive/breathing-exo-daemon/display/display-shm.c')
| -rw-r--r-- | archive/breathing-exo-daemon/display/display-shm.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/archive/breathing-exo-daemon/display/display-shm.c b/archive/breathing-exo-daemon/display/display-shm.c new file mode 100644 index 0000000..435077a --- /dev/null +++ b/archive/breathing-exo-daemon/display/display-shm.c @@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/mman.h> +#include <fcntl.h> +#include <sys/stat.h> + +#define SHM_NAME "/breathing_color_shm" // Shared memory name (same as in exo.c) +#define COLOR_SIZE 8 // Size for one color (e.g., #RRGGBB) + +int main() { + int shm_fd; + char *shm_ptr; + + // Open shared memory object + shm_fd = shm_open(SHM_NAME, O_RDONLY, 0666); + if (shm_fd == -1) { + perror("Failed to open shared memory"); + return 1; + } + + // Map shared memory into the process's address space + shm_ptr = mmap(NULL, COLOR_SIZE, PROT_READ, MAP_SHARED, shm_fd, 0); + if (shm_ptr == MAP_FAILED) { + perror("Failed to map shared memory"); + close(shm_fd); + return 1; + } + + // Read the color from shared memory and print it + printf("Breathing color: %s\n", shm_ptr); + + // Clean up + munmap(shm_ptr, COLOR_SIZE); + close(shm_fd); + + return 0; +} + |
