Shmget: invalid argument. Why am I getting this error?

I get the error "shmget: Invalid argument" when I try to execute this piece of code

int *nFS, *spb, *cell1, shmid; key_t key = 5768; //i need a shared memory segment in which i can put 3 ints if ((shmid = shmget(key, (sizeof(int) * 3), IPC_CREAT | 0666)) < 0 ) { perror("shmget"); exit(1); } if ((spb = (int)shmat(shmid, NULL, 0))== -1 ){ perror("shmat"); exit(1); } cell1= spb + 1 ; nFS= cell1 + 1; //i try to assign here 7 to nFS *nFS=7; 

something is wrong here, but I canโ€™t understand that. Could you help me?

Thanks, Alex.

+4
source share
1 answer

From the shmget (1) man page:

EINVAL A new segment must be created and the size <SHMMIN or size> SHMMAX, or a new segment should not have been created with the specified key, but the size is larger than the size of this segment.

You should check if you have a segment for this key using ipcs and delete it using ipcrm .

+12
source

Source: https://habr.com/ru/post/1385316/


All Articles