Ipc:interprocesscommunication inter-process communication.
The persistence of IPC objects:
Ongoing with process: pipelines, mutexes, condition variables, read and write locks, fcntl record lockout, sockets, POSIX memory-based semaphores
Persistent with the kernel: Message Queuing, semaphores (POSIX-known semaphores and System V semaphores), shared memory
In the CS architecture, the iterative server may have a denial-of-service attack (DoS), so be aware of how long it may be blocked and blocked.
Ways to resolve Dos attacks:
1. The blocking setting time-out in the iteration server.
2. Use a parallel server.
The best solution to producer consumer problems is the IPC, which avoids the creation of deadlocks;
Producers put data in buffers and consumers use that data.
----------------------
3 Technologies of IPC:
6 interfaces for passing messages between processes (threads):
1. Piping
2. Message Queuing
3. Procedure Call
6 types of interfaces that are synchronized between processes (threads):
1. Signal volume (two kinds)
2. Mutex Amount
3. Condition variables
4. Read/write Lock
5. Record lock
2 interfaces for shared memory between processes (threads):
1. Anonymous shared memory
2. Well-known shared memory
####################################################
POSIX IPC:
POSIX semaphore:
-lpthread
#include <semaphore.h>
POSIX Message Queuing:
-lrt
#include <mqueue.h>
POSIX shared memory
-lrt
#include <sys/mman.h>
The POSIX IPC functions are library functions and include header files:
#include <fcntl.h>
#include <sys/stat.h>
To create or open an IPC parameter using the appropriate open function:
Name
The name of the IPC, which is the name of thePOSIX IPC in Linux, begins with/ .
Oflags:
O_rdonly: Read-only, not available for semaphores
O_wronly: Write only, only for Message Queuing
O_RDWR: Read and write, cannot be used for semaphores
O_creat: Created if not present, exists to return existing
O_EXCL: Non-sexual creation
O_nonblock: Non-blocking IO, only for Message Queuing
O_trunc: Short cut if present, only for shared memory
Whenoflags=o_creat mode: Specify the permission bit
S_irusr
S_iwusr
S_ixusr
S_irgrp
S_iwgrp
S_ixgrp
S_iroth
S_iwoth
S_ixoth
The above rules apply only to Message Queuing and semaphores, and the shared memory mode must be specified, if no o_creat is specified, then the mode=0 of the shared memory.
####################################################
System V IPC:
System V Signal Volume
#include <sys/sem.h>
System V Message Queuing
#include <sys/msg.h>
System V Shared memory
#include <sys/shm.h>
The IPC functions of System V are both systems calls and files that contain headers:
#include <sys/ipc.h>
#include <sys/types.h>
Use the appropriate get function to create or open IPC using key_t as their name.
The Ftok function converts an existing path and an integer identifier into a key_t value, called the IPC key.
#include <sys/types.h>
#include <sys/ipc.h>
key_t ftok(const char *pathname, int proj_id);
So the name of the IPC for System V is a file,
The IPC name of System V in Linux requires the file to be created in advance to be converted using Ftok.
The kernel maintains an information structure for each IPC object:
struct IPC_PERM
{
IPC Key:
key_t __key;
Owner ID:
uid_t uid;
gid_t GID;
Creator ID:
uid_t cuid;
gid_t Cgid;
Permissions:
unsigned short mode;
unsigned short __seq;
};
View and DELETE commands for the IPC of System V:
IPCS: View IPC for System V
-M: Shared memory
-Q: Message Queuing
-S: Signal volume
IPCRM: Remove IPC for System V
IPC: Inter-process communication