【发布时间】:2020-12-12 12:44:56
【问题描述】:
编辑
GetCurrentProcessId() 和 getpid() 返回不同的值...但 boost 不会。
原问题
我正在编写一个节点插件来添加一个本地本地缓存,以便在作为集群运行时与快速服务器一起使用,以拥有一个公共缓存。我在进程之间使用boost的message_queue作为IPC,并且需要唯一标识发送请求的进程。 Boost 提供boost::interprocess::ipcdetail::get_current_process_id 来获取当前进程id,但是在主进程和子进程中返回相同的进程id。我认为我说子进程也有自己的唯一 ID 是正确的。那么这里到底发生了什么:
回购(这是一个最小的可重复性):https://github.com/t348575/cluster-mem-shared
输出
00007FF95BDC2310
00007FF95BDC2310
00007FF95BDC2310
00007FF95BDC2310
示例js测试文件
require('dotenv').config();
const cluster = require('cluster');
const cache = new (require('./dist/index')).ClusterMemShared(process.env.MODE);
if (cluster.isMaster) {
cluster.fork();
cluster.fork();
cluster.fork();
}
我在c++返回给js的类的构造函数中打印这个
std::cout << bip::ipcdetail::get_current_process_id << std::endl;
【问题讨论】:
-
ipcdetail不是公共 API 的一部分,不应该使用它 -
现在是 C++ 还是 JS 的问题?还请提取并提供minimal reproducible example!
标签: c++ boost node-addon-api