The simple C/C++ program doesn't work. But it must. I have no problem running this program on Red Hat 9.0. The program just calls 4 system calls sequentially: shmget, shmat, shmdt and shmctl. Another words, I create shared memory, attach to it, detach from it and, finally, destroy it. The text of the program is below //================================================================ #include <stdio.h> #include <sys/shm.h> typedef int UShMem; #define RIGHTS 0666 int main() { UShMem id; id = shmget(1590, 8, IPC_CREAT | IPC_EXCL | RIGHTS); if(id == -1) { perror("shmget"); return 1; } void *res = NULL; if ((int)(res = shmat(id, NULL, 0)) == -1) { perror("shmat"); return 1; } if(shmdt(res) < 0) { perror("shmdt"); return 1; } if(shmctl(id, IPC_RMID, NULL) < 0) { perror("shmctl"); return 1; } printf("All done\n"); return 0; } //================================================================ The call to shmctl produces error. If you comment call to shmdt, then shmctl works fine. The program works fine on Red Hat 9.0 and it _must_ work on any POSIX platform as far as I understand... Best regards, Andrey Fomichev Steps to Reproduce: 1. Cut out the program code from the message and place it to main.cpp 2. Type "g++ main.cpp" 3. Run "./a.out". See the result. Actual Results: shmctl: Invalid argument Expected Results: All done
This happens due to kernel configuration parameter, CONFIG_HARDEN_SHM=y You can control it (systemwide) via /proc/sys/kernel/shm_destroy_unused.