This is svshm/svshm_xfr.h (Listing 48-1, page 1002), an example program file from the book The Linux Programming Interface.
The source code file is copyright 2010, Michael Kerrisk, and is licensed under the GNU Affero General Public License, version 3.
This page shows the "distribution" or "book" version of the file (why are there two versions?), or the differences between the two versions. You can switch between the views using the tabs below.
In the listing below, the names of Linux system calls and C library functions are hyperlinked to manual pages from the Linux man-pages project, and the names of functions implemented in the book are hyperlinked to the implementations of those functions.
+/* svshm_xfr.h + + Header file used by the svshm_xfr_reader.c and svshm_xfr_writer.c programs. +*/ #include <sys/types.h> #include <sys/stat.h> #include <sys/sem.h> #include <sys/shm.h> #include "binary_sems.h" /* Declares our binary semaphore functions */ #include "tlpi_hdr.h" +/* Hard-coded keys for IPC objects */ + #define SHM_KEY 0x1234 /* Key for shared memory segment */ #define SEM_KEY 0x5678 /* Key for semaphore set */ #define OBJ_PERMS (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) /* Permissions for our IPC objects */ +/* Two semaphores are used to ensure exclusive, alternating access + to the shared memory segment */ + #define WRITE_SEM 0 /* Writer has access to shared memory */ #define READ_SEM 1 /* Reader has access to shared memory */ #ifndef BUF_SIZE /* Allow "cc -D" to override definition */ #define BUF_SIZE 1024 /* Size of transfer buffer */ #endif struct shmseg { /* Defines structure of shared memory segment */ int cnt; /* Number of bytes used in 'buf' */ char buf[BUF_SIZE]; /* Data being transferred */ };
This page copyright (C) 2013, Michael Kerrisk, mtk AT man7.org