0xygen
0xygen

Reputation: 33

How to map a file to /dev/zero

I want to map a pcap file in /dev/zero and let other program to read the /dev/zero. Is it possible to do? I read the book APUE and saw the Memory mapping of /dev/zero, but I think it is not what I want to do. Is there anyone can help me?

Upvotes: 0

Views: 239

Answers (1)

Daniel Engel
Daniel Engel

Reputation: 163

Your question is a bit confusing.

Let me see if I understand. Please correct me where needed:

  1. You have a .pcap file that you can open and load its contents in a program--let's call the program "A".

  2. You want to make that .pcap file's contents available in memory buffer that you share with another program--let's call the program "B".

  3. Based on the example in the APUE book, your idea is to mmap /dev/zero in program A, copy the contents of the .pcap file into the mapped memory segment, and then expect that when program B also maps /dev/zero, it will see the contents of the .pcap file.

Is that what you're going for?

If so, then I don't think you'll be able to use /dev/zero. Each of the two programs, when it mmap's /dev/zero, will get a separate zero-filled instance of the memory map. The only way for the two programs to share, in that case, would be for one to be a fork() of the other.

However, you could create a named shared memory object other than "/dev/zero" (call it "/tmp/mypcap" or something) and then multiple programs could share it.

Upvotes: 1

Related Questions