Linux shared memory

Linux shared memory … here is a solution to the problem.

Linux shared memory

*Inux programming creates a function that creates shared memory takes a key as one of its arguments…

What does this key mean? How do I use it?

Edit:

Not a shared memory ID

Solution

It is simply a System V IPC (Interprocess Communication) key, so different processes can create or attach to the same shared memory block. The key is usually created using ftok(), which converts the fully specified filename and project ID into a usable key.

Since an application can often use the same file name in all of its different processes (the file name is usually the configuration file associated with your application), each different process gets the same key (or, more likely, if you use the project ID to specify multiple shared memory segments, the same set of keys).

For example, we once had an application that used configuration files handled by our lex/yacc code, so we only used that pathname and an item ID for each different block of shared memory (there were three or four, depending on the purpose of the process in question). This actually makes a lot of sense because it’s parsing and evaluation data from configuration files stored in a shared memory block.

Since no other application on the system should use our configuration file to make keys, there is no conflict. The key itself is not limited to shared memory, it can also be used for semaphores and other IPC mechanisms.

Related Problems and Solutions