42 #define SHMEM_SIZE 2048 43 #define SHMEM_TOKEN "JustSomeDumbQA" 52 signal_handler(
int signum)
58 main(
int argc,
char **argv)
61 signal(SIGINT, signal_handler);
63 key_t key = ftok(
".",
'b');
64 printf(
"Key: 0x%x\n", key);
68 int shmid = shmget(key, SHMEM_SIZE, IPC_CREAT | 0666);
70 perror(
"M: Could not get ID");
74 void *shmem = shmat(shmid, NULL, 0);
75 if ( shmem == (
void *)-1 ) {
76 perror(
"M: Could not attach");
80 memset(shmem, 0, SHMEM_SIZE);
82 header_t *header = (header_t *)shmem;
85 printf(
"M: ptr=0x%lx\n", (
long unsigned int)shmem);
91 shmctl(shmid, IPC_RMID, NULL);
96 int shmid = shmget(key, SHMEM_SIZE, 0);
99 perror(
"S: Could not get ID");
103 void *shmem = shmat(shmid, NULL, 0);
104 if ( shmem == (
void *)-1 ) {
105 perror(
"S: Could not attach");
109 header_t *header = (header_t *)shmem;
111 printf(
"S: ptr=0x%lx header->ptr=0x%lx\n", (
long unsigned int)shmem,
112 (
long unsigned int)header->ptr);
114 if ( shmem != header->ptr ) {
115 printf(
"S: pointers differ, re-attaching\n");
116 void *ptr = header->ptr;
118 shmem = shmat(shmid, ptr, SHM_REMAP);
119 if ( shmem == (
void *)-1 ) {
120 perror(
"S: Could not re-attach");
123 header = (header_t *)shmem;
124 printf(
"S: after re-attach: ptr=0x%lx header->ptr=0x%lx\n",
125 (
long unsigned int)shmem, (
long unsigned int)header->ptr);
Fawkes library namespace.