In system V message queues,
We get a message queue identifier using the msgget()
system call
int msqid = msgget(key, 0666 | IPC_CREAT);
If msqid is the unique queue identifer, then what is the key? Isn't it also a unique queue identifier?
All that man page says is this
The msgget() system call returns the System V message queue identifier associated with the value of the key argument
There is no explanation of what that key actually is. Is it a key for some sort of hash table where the value is a bunch of IPC tools? I've read this post but it's still muddy.
Also people generally use ftok()
to generate a key.
key_t ftok(const char *pathname, int proj_id);
The ftok() function uses the identity of the file named by the given pathname (which must refer to an existing, accessible file) and the least significant 8 bits of proj_id (which must be nonzero) to generate a key_t type System V IPC key
Why would anyone want to generate a unique number by hashing the inode of a file? Personally I think that all processes agreeing to a common number is easier to implement than all processes agreeing to a common file. Is it solely for uniform distribution purposes as this answer states?