我正在使用 boost::interprocess 在两个应用程序之间进行通信。当同一用户启动这两个应用程序时,效果很好。
当其中一个应用程序是一项服务时,它就会失败。
我发现共享媒体实际上是在“TMP”目录中创建的文件。所以它失败了,因为每个应用程序都在自己的“TMP”目录中创建自己的文件。
也许我没有以良好的方式使用它来实现我的特定目的。
有人知道如何解决我的问题吗?
多谢,
尼克
编辑:我尝试使用“ Managed_mapped_file ”。我的问题是 win32 实现正在调用“ CreateFileMapping ”,但没有指定对象的名称。在我的特殊情况下,我认为我需要指定类似“ Global\MyMappedFile ”的内容,以便应用程序和服务都可以查看映射文件。
这是我的另一个Q的变体.我有两个应用程序,X和Y.他们必须在它们之间共享一个COM对象.X将向此对象发送数据,Y将响应此应用程序发送的事件.在任何时候,X或Y都可能被终止,但单身人士需要保持活着,直到两个申请被终止.
应该可以通过这种方式创建一个单独的COM对象,但是如果X首先启动并创建它,Y然后启动并使用它,然后X停止并...单身人士会怎么样?
无论如何,有没有人用Delphi试过这个?
我想用boost编写一个简单的应用程序,将字符串对象传递给其他进程.它编译得很好,但是当我尝试从第二个进程打印出字符串时,以下消息被放入控制台并且第二个进程崩溃:
../boost_1_44_0/boost/interprocess/sync/posix/interprocess_recursive_mutex.hpp:107:void boost :: interprocess :: interprocess_recursive_mutex :: unlock():断言`res == 0'失败.
第一个流程代码:
shared_memory_object::remove(SHARED_MEMORY_NAME);
managed_shared_memory mshm(create_only, SHARED_MEMORY_NAME, SHARED_MEMORY_SIZE );
mshm.construct<string>( IP_STRING_NAME )("Message to other process");
string syscall(argv[0]);
std::system( (syscall+" &").c_str() ); //starting second process
Run Code Online (Sandbox Code Playgroud)
第二个流程代码:
managed_shared_memory mshm( open_or_create, SHARED_MEMORY_NAME, SHARED_MEMORY_SIZE );
std::pair<string * , size_t > p= mshm.find<string>(IP_STRING_NAME);
cout<<"string is "<<*p.first<<endl;
Run Code Online (Sandbox Code Playgroud)
如何使我的应用程序以正确的方式工作?
如果它是硬件信号量,如何从软件中使用它?是否有在硬件中实际实现的软件 API?
我在实现固件以连接到某些硬件时询问。硬件和固件之间将进行大量信息交换。我经常谈论硬件信号量,只是想了解有关它的更多信息。一些关于这方面的文献会有所帮助
有没有办法在两种不同的服务之间进行通信?我有一个已经运行的服务.有没有办法创建第二个服务,可以附加到第一个服务,并发送和接收日期?
我还想从控制台应用程序访问Windows服务并附加到它.可能吗?
我有一个控制台应用程序,我试图让它一次只运行一次。我使用了 boost 进程间库 shared_memory_object 来做到这一点。请参阅下面的代码片段,
boost::scoped_ptr<shared_memory_object> sharedMem;
try
{
sharedMem.reset(
new shared_memory_object(create_only, "shared_memory", read_write));
} catch(...)
{
// executable is already running
cerr << "Another instance of this program is running!" << endl;
return 1;
}
// do something
shared_memory_object::remove("shared_memory"); // remove the shared memory before exiting the application
Run Code Online (Sandbox Code Playgroud)
问题是,该方法阻止我的应用程序同时运行多次;但是,假设用户停止程序运行,那么内存不会被释放,下次当用户再次尝试运行该程序时,它不会运行。你有什么建议吗 ?
PS C++ 控制台应用程序,操作系统:Ubuntu(但也可以在其他平台上运行的解决方案将是完美的)。谢谢
我们想支持最近停产的一些硬件.硬件的驱动程序是一个普通的32位C DLL.我们没有源代码,并且(出于法律原因)对驱动程序的反编译或逆向工程不感兴趣.
硬件快速发送大量数据,因此通信协议需要非常高效.
我们的软件是原生的64位C++应用程序,但我们希望通过32位进程访问硬件.什么是32位和64位应用程序相互通信的有效,优雅的方式(理想情况下,这不涉及发明新协议)?
解决方案应该是C/C++.
更新:一些受访者要求澄清这是用户模式还是内核模式驱动程序.幸运的是,它是一个用户模式驱动程序.
正如本文所述,有两种方法可以在C#中调用另一个进程.
Process.Start("hello");
Run Code Online (Sandbox Code Playgroud)
和
Process p = new Process();
p.StartInfo.FileName = "hello.exe";
p.Start();
p.WaitForExit();
Run Code Online (Sandbox Code Playgroud)
Process.Start()?我喜欢创建一个包含进程间容器的类的boost进程间向量.以下代码一直有效,直到resize函数调用,当然因为我的类没有默认构造函数.我该如何解决这个问题?该示例基于容器的boost 容器示例
谢谢马库斯
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/containers/string.hpp>
using namespace boost::interprocess;
//Typedefs of allocators and containers
typedef managed_shared_memory::segment_manager segment_manager_t;
typedef allocator<void, segment_manager_t> void_allocator;
typedef allocator<int, segment_manager_t> int_allocator;
typedef vector<int, int_allocator> int_vector;
typedef allocator<char, segment_manager_t> char_allocator;
typedef basic_string<char, std::char_traits<char>, char_allocator> char_string;
class complex_data
{
public:
int id_;
char_string char_string_;
int_vector int_vector_;
//Since void_allocator is convertible to any other allocator<T>, we can simplify
//the initialization taking just one allocator for all inner containers.
complex_data(const …Run Code Online (Sandbox Code Playgroud) 我现在正在使用共享内存boost::interprocess.
我已经按以下方式定义了一些std::unordered_map和std::unordered_set类型:
#include <boost/interprocess/allocators/allocator.hpp>
#include <unordered_map> // NOT the boost implementation ...
...
namespace ipc = boost::interprocess;
/**
* allocator type needed to construct maps in shared memory
*/
typedef ipc::allocator<std::pair<const size_t, std::string>,
ipc::managed_shared_memory::segment_manager> OBJ_MAP_ALLOCATOR;
/**
* map type to construct maps in shared memory
*/
typedef std::unordered_map<size_t,
std::string,
std::hash<size_t>,
std::equal_to<size_t>,
OBJ_MAP_ALLOCATOR> OBJ_MAP_TYPE;
Run Code Online (Sandbox Code Playgroud)
我把它们初始化为:
ipc::managed_shared_memory segment;
// allocate segment etc ...
OBJ_MAP_ALLOCATOR alloc_inst(segment.get_segment_manager());
objMap = segment.find_or_construct<OBJ_MAP_TYPE> (ipc::unique_instance)(alloc_inst);
Run Code Online (Sandbox Code Playgroud)
这似乎工作正常,我没有在编译或运行时(在Apple LLVM version 9.1.0 (clang-902.0.39.1)使用C++ …
interprocess ×10
boost ×5
c++ ×4
c# ×2
containers ×2
allocator ×1
com ×1
delphi ×1
delphi-2007 ×1
ipc ×1
linux ×1
process ×1
semaphore ×1
stl ×1
terminology ×1
vector ×1
winapi ×1
windows ×1