http://www.ibm.com/developerworks/cn/linux/l-ipc/
https://www.ibm.com/developerworks/cn/linux/l-ipc/part1/
Http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index1.html
Http://www.ibm.com/developerworks/cn/linux/l-ipc/part2/index2.html
Linux supports at least the following IPC mechanisms: (both POSIX and System V-mode) pipelines, popen (collaborative processes), FIFO System v semaphores, message queues, shared memory----------with the kernel, and when the key value is generated, The path parameter must refer to an existing file. Do not support ls,rm,chmod,select,poll ... Message Queuing overcomes the lack of information load, the pipeline can only host unformatted byte streams and buffer size limitations. POSIX's ... -------with kernel or file. Fast User space Mutex UNIX domain socket--------The fastest available IPC form for shared memory with the process. is designed for the low efficiency of other communication mechanisms. It is often used in conjunction with other communication mechanisms, such as semaphores, to achieve synchronization and mutual exclusion between processes. Signal:kill, raise, Alarm, abort and Setitimer and Sigqueue function Note: Do not have such a misunderstanding: Sigqueue () sent, sigaction installed signal is reliable. In fact, a reliable signal is a new signal added later (the signal value is between sigrtmin and Sigrtmax), and the unreliable signal is a signal with a signal value less than sigrtmin. The reliability and unreliability of the signal are only related to the signal value, which is independent of the signal sending and installing function. HUP INT QUIT ILL TRAP abrt bus fpe KILL USR1 segv USR2 PIPE alrm TERM stkflt chld CONT STOP tstp ttin ttou URG xcpu xfsz V TALRM PROF Winch POLL PWR SYS rtmin rtmin+1 rtmin+2 rtmin+3 RTMAX-3 RTMAX-2 the RTMAX-1 Rtmax streams the IPC mechanism, which Linux itself does not support, has a separate Install packages; You can communicate across PC processes; mutexes or condition variables: Dynamic initialization (not statically allocated), which can also be used for synchronization between processes in shared memory; Read and write locks: non-standard
1. Pipeline: -----------continuity with process; Linux only supports Half-duplex mode; Reference Source: OpenSSH, Do_cmd function in Scp.c.
Streaming mode, no boundaries (similar to TCP); cannot be randomly accessed (such as Lseek), must be sequentially accessed; if all the write ends are close, then EOF is detected after reading all the data, and the read end is required to close the write socket when the process on which the read end is started. Cannot read EOF; If all the read ends are close,write, it will cause a sigpipe signal, a default kill process, or a epipe error if the handle ignores this signal, and the write end is required to close the read socket when the process is started. Otherwise the writing end can be written until the buffer is full, and some UNIX implementations of the pipe are full-duplex, called stream pipes. ---non-standard, it is best not to rely on this syntax. If necessary, you can use the UNIX domain socket pairs (socketpair function); data less than or equal to PIPE_BUF can be transmitted once, that is, atomic operation; (Fpathconf (FD, _PC_PIPE_BUF); The system has the most Large cache capacity, generally do not need to consider, read end as soon as possible. The minimum page size, the maximum/proc/sys/fs/pipe-max-size, can be set by Fcntl (FD, F_SETPIPE_SZ, size), Fcntl (FD, F_GETPIPE_SZ) to read this value; Generally use read, write operations, or you can use Fdopen to get the file pointer files *, using the stdio function, such as printf (), scanf (), and so on, starting from 2.6.27, support non-standard pipe2, which provides two flag:o_ Cloexec and O_nonblock O_nonblock can also be implemented through FCNTL, allocating file descriptors from small to large to find idle file descriptors;
2. FIFO:
Persistence goes with the process, but when the last referenced process terminates, the data is deleted and the name remains until the display is deleted. Mkfifo blocking mode Open, two of the process to open the FIFO order required to cross, otherwise prone to deadlock; non-blocking mode open, if it is only write FIFO, must have read open, otherwise return Enxio error, pipe_buf size of the write operation for atomic operation; Open_ Max number of descriptors opened at any time for a process;
3. Message Queuing:
Disadvantage: Select and poll are not supported because they are not file descriptors. Do not know the source of the message, need to carry information inside the message to show.
1) System V:msgget
Returns any message of the specified priority;
Mq_notify mechanism is not supported;
2 POSIX (compared to system V, preferably Posix): Mq_open,mq_unlink,mq_close, Mq_timedsend, Mq_timedreceive, Mq_getattr, Mq_setattr, mq_ Notify
Always returns the highest priority message;
4. POSIX shared Memory:
1 memory-mapped file mode; open + mmap; persistence with file;
2 Shared Memory Area object, that is, memory mapped object mode; Shm_open + mmap; persistence with kernel;-----------------------a process modifies shared memory and requires notification to other processes that the shared memory has changed.
3 the size of the shared memory object can be modified by ftruncate;
5. System v Shared Memory:
1 The size of the shared memory object is fixed when the call Shmget is created;
Synchronous:
1. System V sem:------Kernel maintenance, can be used for process or thread synchronization;
1 file Mode: First create the file, then Ftok,semget,semctl,semop
2. Mutex: Mutual-exclusion lock is a cooperative lock, cannot be enforced, lock and lock properties must be placed in shared memory when used between processes;
PTHREAD_MUTEXATTR_INIT,PTHREAD_MUTEXATTR_SETPSHARED,PTHREAD_MUTEXATTR_SETROBUST_NP 3. Condition variable:
When used between processes, it must be placed in shared memory; When a condition variable wakes, a thread, or all threads, can be awakened; 4. Read and Write Lock: Pthread_rwlock_init. 5. Record lock ...
6. POSIX semaphore:------ can be used for process or thread synchronization;
1 well-known signal volume: stored in the file system; sem_open,sem_close,sem_unlink; with the kernel; only sem_unlink really remove SEM; allocate memory automatically;----relatively useful
2 Memory based Semaphore: stored in shared memory; Sem_init, sem_destory; the caller allocates memory; The caller decides whether to use it either between processes or within processes;---the caller allocates memory, which is generally part of shared memory. Sem_init the second argument int shared if 0, is a process thread share; If 1, it must be shared memory for process access and for shared between processes.