ftok在内核中创建一个进程间都看得到的标识
#include <sys/types.h>
#include <sys/ipc.h>
key_t ftok(const char *pathname, int proj_id);
pathname相当于这个 标识符在那个目录,proj_id就是相当于一个密码,在相同的pathname,用相同的 proj_id就可以获取到 相同的 key_t 也就是那个 msgfd。
代码Demo
msgcomm.h
#ifndef _MSGCOMM_H_
#define _MSGCOMM_H_
#include <iostream>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
#define PATH "."
#define PROJ_ID 0x666