#include #include #include #include int main() { char s[100]; int key = ftok("share.c", 1); printf("key = %d\n", key); int id = shmget(key, 1024, 0777 | IPC_CREAT); printf("id = %d\n", id); void * ptr = shmat(id, (void *)0x800000, 0); printf("address is %016llX\n", ptr); int * array = (int *)ptr; int * other = 10 + (int *)ptr; // for example printf("array[0] = %d\n", array[0]); array[0] += 111; printf("array[0] = %d\n", array[0]); fgets(s, 99, stdin); array[0] += 111; printf("array[0] = %d\n", array[0]); array[0] += 111; printf("array[0] = %d\n", array[0]); int r = shmdt(ptr); printf("shmdt r = %d\n", r); r = shmctl(id, IPC_RMID, NULL); printf("shmctl r = %d\n", r); }