blob: 435077a0baabaff00e593449162c0e70ba272168 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}
|