ALT Linux Bugzilla – #6053
A simple program that uses shared memory doesn't work
Last modified: 2005-09-04 23:37:16
You need to
before you can comment on or make changes to this bug.
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
typedef int UShMem;
#define RIGHTS 0666
id = shmget(1590, 8, IPC_CREAT | IPC_EXCL | RIGHTS);
if(id == -1)
void *res = NULL;
if ((int)(res = shmat(id, NULL, 0)) == -1)
if(shmdt(res) < 0)
if(shmctl(id, IPC_RMID, NULL) < 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...
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.
shmctl: Invalid argument
This happens due to kernel configuration parameter, CONFIG_HARDEN_SHM=y
You can control it (systemwide) via /proc/sys/kernel/shm_destroy_unused.