[英]node addon with cluster get process id returns same id for all forked process's
GetCurrentProcessId() and getpid() return different values... but boost does not. GetCurrentProcessId() 和 getpid() 返回不同的值......但 boost 没有。
I am writing a node addon to add a local native cache to be used with an express server when running as a cluster, to have a common cache.我正在编写一个节点插件来添加一个本地本机缓存,以便在作为集群运行时与快速服务器一起使用,以拥有一个公共缓存。 I am using boost's message_queue
for IPC between the process's, and need to uniquely identify the process sending the requests.我在进程之间为 IPC 使用 boost 的message_queue
,并且需要唯一标识发送请求的进程。 Boost provides boost::interprocess::ipcdetail::get_current_process_id
to get the current process id, but the same process id is returned in the main process and the child process's. boost提供了boost::interprocess::ipcdetail::get_current_process_id
来获取当前进程id,但是主进程和子进程返回的进程id相同。 I think I am right in saying that child process's have their own unique ID as well.我认为我说子进程也有自己的唯一 ID 是正确的。 So what exactly is going on here:那么这里到底发生了什么:
Repo (it is a minimal reproducible): https://github.com/t348575/cluster-mem-shared回购(这是一个最小的可重复性): https://github.com/t348575/cluster-mem-shared
00007FF95BDC2310
00007FF95BDC2310
00007FF95BDC2310
00007FF95BDC2310
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();
}
std::cout << bip::ipcdetail::get_current_process_id << std::endl;
Like I said, that's an undocumented implementation detail.就像我说的,这是一个未记录的实现细节。
However, if this is really your code:但是,如果这确实是您的代码:
std::cout << bip::ipcdetail::get_current_process_id << std::endl;
Then the obvious fix is to call the function instead of printing its address:然后明显的解决方法是调用function 而不是打印其地址:
std::cout << bip::ipcdetail::get_current_process_id() << std::endl;
Note the operator()
注意operator()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.