As far as I understand errno 22 in case of shmget is becasue A shared memory segment is to be created and the value of size is less than the system-imposed minimum or greater than the system-imposed maximum.
But something which I dont understand is I am calling shmget in my server twice first time with key_id as IPC_PRIVATE and size as 64K and second time as key_id as some random number let say 200 and size as 64K and it always fails.
I tried reducing the size of second instance and behaviour which I am seeing is something which I am not able to understand
For key_id greater than 250 the second instance allow only only till size 8k for key_id between 200 and 250 it allow me till 16K and for key_id less than 200 it allows me till 32000 bytes.
Also when I changes the order that is call the shmget with random key_id first and then with IPC private with size as 64K for both, it works fine.
Any pointers on why the key_id plays such an improtant role in first scenario. And why calling shmget with random key_id and then IPC_PRIVATE works but other way doesnt