43 #define SHMEM_SIZE 2048
44 #define SHMEM_TOKEN "JustSomeDumbQA"
54 signal_handler(
int signum)
60 main(
int argc,
char **argv)
62 signal(SIGINT, signal_handler);
64 key_t key = ftok(
".",
'b');
65 printf(
"Key: 0x%x\n", key);
69 int shmid = shmget(key, SHMEM_SIZE, IPC_CREAT | 0666);
71 perror(
"M: Could not get ID");
75 void *shmem = shmat(shmid, NULL, 0);
76 if (shmem == (
void *)-1) {
77 perror(
"M: Could not attach");
81 memset(shmem, 0, SHMEM_SIZE);
83 header_t *header = (header_t *)shmem;
86 printf(
"M: ptr=0x%lx\n", (
long unsigned int)shmem);
92 shmctl(shmid, IPC_RMID, NULL);
97 int shmid = shmget(key, SHMEM_SIZE, 0);
100 perror(
"S: Could not get ID");
104 void *shmem = shmat(shmid, NULL, 0);
105 if (shmem == (
void *)-1) {
106 perror(
"S: Could not attach");
110 header_t *header = (header_t *)shmem;
112 printf(
"S: ptr=0x%lx header->ptr=0x%lx\n",
113 (
long unsigned int)shmem,
114 (
long unsigned int)header->ptr);
116 if (shmem != header->ptr) {
117 printf(
"S: pointers differ, re-attaching\n");
118 void *ptr = header->ptr;
120 shmem = shmat(shmid, ptr, SHM_REMAP);
121 if (shmem == (
void *)-1) {
122 perror(
"S: Could not re-attach");
125 header = (header_t *)shmem;
126 printf(
"S: after re-attach: ptr=0x%lx header->ptr=0x%lx\n",
127 (
long unsigned int)shmem,
128 (
long unsigned int)header->ptr);
Fawkes library namespace.