提振间,第二个过程中不能打开由第一个过程中创建的共享内存 [英] boost interprocess, 2nd process can't open the shared memory created by 1st process

查看:142
本文介绍了提振间,第二个过程中不能打开由第一个过程中创建的共享内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个Windows应用程序,它需要共享多个实例(进程)之间的一些日期。我选择使用升压进程间。经过一番调查,我发现managed_windows_shared_memory是最适合我的情况。但第二个进程无法打开共享内存一号过程中产生的。

I'm writing a Windows application, which needs to share some date between multiple instances (processes). I choose to use boost interprocess. After some investigation, I find managed_windows_shared_memory is best for my situation. But 2nd process can't open shared memory created by 1st process.

code为第一次例如:

Code for 1st instance:

#include <boost/interprocess/managed_windows_shared_memory.hpp>
using namespace boost::interprocess;
typedef boost::interprocess::managed_windows_shared_memory SharedMemory;

SharedMemory sharedMemory(create_only, "MyTestSharedMemory", 65535);

code的第二个实例:

Code for 2nd instance:

#include <boost/interprocess/managed_windows_shared_memory.hpp>
using namespace boost::interprocess;
typedef boost::interprocess::managed_windows_shared_memory SharedMemory;

try
{
    SharedMemory sharedMemoryT(open_only, "MyTestSharedMemory");
}
catch (interprocess_exception &ipce)
{
    if (ipce.get_error_code() == not_found_error)
    {
        ::OutputDebugStringA("Not found");
    }
}

我敢肯定,当第二个实例试图打开共享内存,比如一号进程仍在运行(不退出)。

I'm sure when 2nd instance trying to open the shared memory, 1st instance process is still running (not exited).

通过运行accesschk.exe,我敢肯定,创建共享内存系统对象,当第二个实例试图打开它仍然退出。下面是这个共享内存的输出。在这里,我的域,我的账户和我的域账户有实际值在我的环境。

By running accesschk.exe, I'm sure the shared memory system object is created and still exiting when 2nd instance trying to open it. Here is the output about this shared memory. Here "my-domain", "my-account" and "my-domain-account" have actual values in my environment.

\Sessions\5\BaseNamedObjects\MyTestSharedMemory
  Type: Section
  Medium Mandatory Level (Default) [No-Write-Up]
  RW NT AUTHORITY\SYSTEM
    SECTION_ALL_ACCESS
  RW my-domain\my-account
    SECTION_ALL_ACCESS
  RW my-domain\my-domain-account
    SECTION_ALL_ACCESS

每一次,第二个实例被not_found_error。如果我尝试先创建共享内存,然后尝试在相同的情况下,它的成功将其打开。任何想法?我在Windows 8.1。

Every time, 2nd instance gets "not_found_error". If I try to create shared memory first and then try to open it in same instance, it successes. Any idea? I'm on Windows 8.1.

更多信息。
这两种情况下,在同一个用户帐户相同的会话中运行。

More information. These two instances run in same session with same user account.

我试图在第二个实例1实例和OpenFileMapping使用Windows API的CreateFileMapping,它工作得很好!

我还试图用升压managed_shared_memory代替managed_windows_shared_memory,它也可以。

然后我试图使用boost windows_shared_memory,比如1号创建成功,但第二个实例无法找到它。

貌似有升压一些问题,共享内存类(managed_windows_shared_memory / windows_shared_memory)本机窗口。

推荐答案

我的最好的办法是你不是在同一个运行的会议的作为创建共享内存区域(服务器进程注意 \\会话\\ 5 命名空间preFIX)。

My best bet is you're not running in the same session as the 'server' process that creates the shared memory area (note the \Sessions\5 namespace prefix).

这当一个进程作为服务运行或以其他方式冒充不同的帐户通常发生(ASP思考/ IIS工人,Citrix /终端服务器会话等)

This usually happens when one process runs as a service or otherwise impersonating a different account (think ASP/IIS workers, Citrix/Terminal server sessions etc.)

这篇关于提振间,第二个过程中不能打开由第一个过程中创建的共享内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆