How to choose the "Key" for inter-processes communication in Linux?

Ara*_*raK 4 linux ipc message-passing

Good Day...

I am doing a homework which states that I have 5 processes; a server and the rest are clients. Each process is supposed to be sparked from a different executable. I am going to implement a two-way message passing solution, but the question is not about message passing per se. Is there an elegant way to communicate the key between those different executables. i.e. when I call the following function:

int msgget(key_t key, int msgflg);
Run Code Online (Sandbox Code Playgroud)

How are other processes supposed to know the key?

It is OK for my homework to use a predetermined key, but I would like to know how it could be done in a real program. Because What "I understand" is there could happen a conflict if an unrelated process asks for the my key in some user's machine.

jsp*_*cal 10

一个约定是使用ftok()man生成一个唯一的密钥

ftok()函数使用由给定路径名(必须引用现有的可访问文件)命名的文件的标识和proj_id的最低有效8位(必须为非零)来生成key_t类型System V IPC密钥,适用于msgget(2),semget(2)或shmget(2).

当使用相同的proj_id值时,对于命名同一文件的所有路径名,结果值是相同的.当(同时存在的)文件或项目ID不同时,返回的值应该不同.

  • 通过在客户端中使用相同的参数运行ftok. (2认同)