简体   繁体   English

两个进程共享同一个pcap文件

[英]Two processes sharing same pcap file

I have a c++ program (executing on linux) which makes use of a pcap file. 我有一个c ++程序(在linux上执行),它使用了一个pcap文件。 Each packet from this pcap file is processed and results are generated in a text file. 处理来自该pcap文件的每个数据包,并在文本文件中生成结果。 I have written a script that run two instances of this program with different input arguments . 我编写了一个脚本,使用不同的输入参数运行该程序的两个实例。 One instance of this program runs on one CPU and the other instance runs on second CPU. 该程序的一个实例在一个CPU上运行,另一个实例在第二个CPU上运行。

The problem is that in my program I have hard coded the pcap file name. 问题是在我的程序中,我已经硬编码了pcap文件名。 As a result, on both CPUs the pcap file is opened and packets are read from it. 结果,在两个CPU上都打开了pcap文件,并从中读取了数据包。

I want that instead both of the programs open up the same pcap file for reading, this thing happens just once that one time a pcap file is opened and each of its packet is send to both the processes running on CPU1 and CPU2. 我希望不是两个程序都打开相同的pcap文件进行读取,而是一次打开一个pcap文件并将其每个数据包发送到在CPU1和CPU2上运行的两个进程中,就发生了这种情况。

Please give me some direction that how can I achoeve this task. 请给我一些指导,告诉我如何完成这项任务。

It sounds like you want your processes to do something like this: 听起来您希望您的流程执行以下操作:

  1. Open up your pcap file 打开你的pcap文件
  2. Read some packet out of it 从中读取一些数据包
  3. Pass that packet onto two threads of your process, each one configured differently 将该数据包传递到流程的两个线程中,每个线程配置不同

You could have your script read the pcap file and pass binary data on stdin to your c++ program which then processes it. 您可以让脚本读取pcap文件,并将stdin上的二进制数据传递给c ++程序,然后由c ++程序进行处理。 Or you could use a socket, shared memory a pipe instead of stdin. 或者,您可以使用套接字,共享内存使用管道而不是stdin。

I'm assuming that you have access to the code for the program of which you speak. 我假设您可以访问所讲程序的代码。

If not, then it's much more complicated. 如果没有,那就复杂得多了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM