问题
Could you please help me? I can not increase the size of my Sherd Memory. The code is written in C on Linux.
I need 65536 bytes, but just 49152 seem to be allowed... If I increase it, shmget fails...(in my code: shmid < 0)
I tried to find out my maximum shared memory size and increased it with:
sysctl -w kernel.shmmax=2147483648
But that doesn't help, the initialization again fails.
This is my code:
#define SHM_KEY 9877
#define SHM_SIZE 65536
int SHM_init (int shmid, char** shm, key_t key, long int size) {
/* Create a new (System V) shared memory segment of the specified size */
shmid = shmget(key, SHM_SIZE, IPC_CREAT|0777);
/* Check if SHM creation was successful */
if (shmid < 0) {
/* DBG: Debug message to show which point of the program has been passed */
DBG_PRINT("C\n");
/* Check if creation failed because of already existing SHM */
if (EEXIST == errno) {
/* DBG: Debug message to show which point of the program has been passed */
DBG_PRINT("CC\n");
/* Delete already existing SHM with shmctl */
shmctl(shmid, IPC_RMID, NULL);
} else {
/* DBG: Debug message to show which point of the program has been passed */
DBG_PRINT("CCC\n");
}
/* Creation and initialization of SHM failed */
return -1;
}
/* Attach the SHM data pointer to the previously created SHM segment */
*shm = shmat(shmid, NULL, 0);
if(*shm == (char *) -1) {
/* Attaching failed */
return -1;
}
DBG_PRINT("Shared Memory Initialization successful\n");
/* Creation and initialization of shared memory was successful */
return 0;
}
Thank you so much in advance...
回答1:
This topic might help.
What does ipcs -l return if you increase the shmmax with sysctl -w kernel.shmmax=2147483648 ?
来源:https://stackoverflow.com/questions/34471969/can-not-increase-size-of-shared-memory