The various comminucation facilities allow processes to exchange data with one another
DPDK is a set of libraries and drivers for fast packet processing
We can further break data-transfer facilities into the following subcategories
#include <unistd.h>
int pipe(int filedes[2]);
/*
* Returns 0 on success, or -1 on error
*/
#include <stdio.h>
FILE *popen(const char *command, const char *mode);
/*
* Returns file stream or NULL on error
* mode is w: calling process write to command
* mode is r: calling process read from command
*/
int pclose(FILE *stream);
/*
* Returns termination status of child process, or -1 on error
*/
Separating messages in a byte stream:
Synchronization between the reader and writer processes is automatic
#include <sys/stat.h>
int mkfifo(const char *pathname, mode_t, mode);
/*
* Returns 0 on success, or -1 on error
*/
Although shared memory provides fast communication, this speed advantage is offset by the need of synchronize operations on the shared memory.
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker.
shm API | description |
---|---|
shmget | allocate shared memory segment |
shmat | attach to the shared memory with the given shared memory identifier |
shmctl | perform control operations on the shared memory segment |
shmdt | detaches from the shared memory |
To use the above API we must include
<sys/ipc.h>
and
<sys/shm.h>
header files.
int shmget(key_t key, size_t size, int shmflg);
shmget
returns the shared memory ID on success.
key
must be unique. This key
can be generated using the ftok()
call.size
argument is the size of the shared memory segment (it is rounded to the multiples of PAGE_SIZE. Usually PAGE_SIZE is 4k).shmflg
is usually set with the IPC_CREAT flag. key
already exist, the errno
is set to EEXIST and returns -1.ipcs - show information on IPC facilities
void *shmat(int shmid, const void *shmaddr, int shmflg);
The API shmat
performs the attachement to the shared memory segment.
shmid
is the id returned from shmget.