Well, usually you should use the file associated with the application itself.
For example, we had an application that loaded a configuration file into shared memory (in a parsable, efficient way — think of an XML file that was converted to memory structures with quick pointers, etc.), and we created a shared memory segment from ftok obtained from the configuration file itself.
In the worst case, if you do not have configuration files for your application, try using the executable itself. You can be sure that it exists in the system somewhere (since you run it).
You are also not limited to files, you can use /etc yourself or /tmp or even / if you need.
I say "if necessary" because it is a little dangerous. Calling ftok will give you a unique key based on the specifications of your file and your identifier. If you use your own file, for example /etc/andrew.conf , you can be sure that you will not encounter any other ftok listed key.
However, if you and everyone else decided to use /tmp as part of the file specification, then the only difference is the identifier. Therefore, it is much easier to get a collision with other keys.
What I always did was use the file specification as a truly unique value for my application, and then just use the identifier for the specific thing I want to create.
So, if I need 27 semaphores and 15 blocks of shared memory, they all use /etc/pax.conf as a file specification and identifiers from 1 to 42 (and my application knows which identifier refers to which object).
paxdiablo
source share