I am having problems with the shmget function. The code compiles correctly, but I get the error "shmget: Invalid argument" when I execute it. I am compiling on a Sparcstation 20 running solaris 2.6 and using the sun workshop c compiler v4.2.
Does anyone have any idea why this is failing?
I include the code for my small program below:
* shm_server.c - Program to test passing information between
* processes using shared memory
* Creates the string and shared memory portion.
/* #define SHMSZ 27 */
int msgflg = IPC_CREAT | 0666;
* We will name our shared memory segment
key = 5678;
size = 27;
* Create the segment.
printf("shmget( %i, %i, %o)\n", key, size, msgflg);
/* shmid = shmget(key, SHMSZ, msgflg); */
shmid = shmget(key , size, IPC_CREAT | 0666);
if ( shmid < 0 )
* Now we attach the segment to our data space.
if ( (shm = shmat(shmid, NULL, 0)) == (char *) -1 )
* Now we put some things into the memory for the
* other process to read.
s = shm;
for (c = 'a'; c <= 'z'; c++)
*s++ = c;
*s = NULL;
* Finally, we wait until the other process
* changes the first character of our memory
* to '*', indicating that it has read what
* we put there.
while (*shm != '*')