How it works...

Running the ./user1 and ./user2 programs would give the following interactions:

Let's perform the steps, as follows:

  • Step 1: The first step just includes a few headers we need: stdio.h for the standard input/output (for example, perror , printf, and so on); mman.h for the shared memory APIs; mmap and fcntl.h for the shm_open flags (for example, O_CREAT, O_RDWR, and many others); unistd.h for the ftruncate method; and string.h for strlen and memcpy methods.

We defined STORAGE_ID1 and STORAGE_ID2 to identify the two shared memory objects, which will be available in the /dev/shm folder:

root@1f5b72ed6e7f:/BOOK/chapter6# ll /dev/shm/SHM_USER* ...

Get C++ System Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.