What is this "project identifier" in ftok()?

1k Views Asked by At

The second parameter proj_id. What is it?

#include <sys/types.h>
#include <sys/ipc.h>
key_t ftok (const char *pathname, int proj_id);
1

There are 1 best solutions below

0
On

There is a key and identifier based data structure with respect to the implementation of ftok ( where inode of the file from the path you gave and unique id associated with is attached).

So you can use any int value for proj_id so that the return value associcated with it will be common when referenced with same proj_id.

I tested it out by changing the proj_id and having the same file and then changing back to same proj_id (n-1). And my experiment worked. Where having same proj_id i was only be able assign 1 semaphore with the ftok key_id passed. But when I changed the proj_id and sending the same file path I was able to get new semaphore. ( remember to use nano for chaning as vim when using :wq option will change the inode number of the file).

For reference : https://pubs.opengroup.org/onlinepubs/9699969699/functions/ftok.html