Verbatim https://www.dazhuanlan.com/2019/08/26/5d632d2a07f58/
IPC use category
This article has nothing to do with pictures and purely fun
Relative to do something, we want to sleep late, but relative to sleep, I want to write summary!
Today the blog's git
branch confused, wasted little time. Then introduce today about inter-process communication ( IPC
). Interprocess communication, from the << UNIX
2 Network Programming Volume: interprocess communication >> last chapter of Sun RPC talk, then why? Because we have a thing to grasp, because it is certainly valuable, we go to learn if some do not have the technology now, out of, then we do not need to get to the bottom, only to learn their thoughts, you can kick the tires.
Finally, a summary section is introduced, when building an application process, we first make a choice between:
(1) constructing a large single process, all the work is completed;
(2) the entire process applied to a walk in a plurality of processes communicating with each other.
If we choose the latter, the next choice is:
This book is mainly concerned with 2a
this situation, that is, use 消息传递
, 共享内存
and may use some form 同步
for inter-process on the same hostIPC
. Within the same process between different threads IPC
and different processes between the various threads IPC
just a special case of this situation.
The application process required for network communication between different parts of the most use to display network programming ( explicit network programming
write) the way we are now popular, is Socket
programmed.
So now what happens then? Thanks to the Internet fire, leading to inter-process communication is now mainstream popular way to use into a Socket
socket communication. This can also be understood, because the Internet is the traditional C/S
(server - client) architecture for client development, the main is the mobile application development, PC
end application development, Web browser development, which is the Internet's main traffic entrance applications and browser objects need to communicate is the server, the server and the client need to do is communicate better, so if you need working on the Internet, then the Socket
program relative to other IPC
means need to be more familiar with, especially in the server backend development, Fortunately, the client, the client business logic and UI
experience relative importance, as some systems layer technology, development framework have been packaged well, you can just learn how to use, like android
, IOS
development. But if you are engaged in system development, then all the IPC
way need to know, in particular 消息传递
, 共享内存
need to understand.
Specific IPC means
signal
Software interrupt notification event handling example: SIGFPE, SIGKILL, SIGUSR1, SIGSTOP , SIGCONT
received signal what will happen:
- Catch: Specifies the signal handler is called
- Ignore: relying on the operating system's default
example: Abort, memory dump, suspend or resume process - Mask: a blocking signal does not occur
may be temporary (the same type of signal processing)
Inadequate: not transmit any data to be exchanged
Features:
- signals are only delivered between processes when either: only transfer between a user of the same process, or the super-user signaling
- the processes involved are run by the same user
- the raising process is run by a superuser
- signal types and type names are defined in signal.h defined in the document signal.h
- signals are not queued signals do not line up
- handlers "terminate process" (SIG_DFL) and "ignore signal" (SIG_IGN) are already defined in signal.h commonly used to terminate the process and ignore signals defined in signal.h
unix
The main interface information:
1 |
|
Pipes and FIFO
1. pipeline, conduit typically refers to the unknown, it is the UNIX
system IPC
of the oldest forms .
Features:
- pipes are uni-directional half-duplex
- with file descriptors, they can only be shared between processes with parent-child relationship can only be used between parent and child
- atomicity is guaranteed for messages shorter than PIPE_BUF bytes cache size specific atomicity
- alf-open pipes are told widowed (or broken) pipes. Writing on them causes a write error, reading from them always returns 0 bytes. bad pipeline, the write error occurs, when read, it returns 0 bytes.
unix
The main interface information:
1 |
|
Simulated usage scenarios, implement Linux
a system call popen
, the main code:
1 |
FILE * vpopen(const char * cmdstring, const char * type) |
2. Named pipes, FIFO,
features:
- Each FIFO has a name associated with the path that allows communication between unrelated processes
- Has the attributes and characteristics of the standard pipe
unix
The main interface information:
1 |
* |
模拟使用场景:
1 |
* 模拟场景 |
具体实现代码:
1 |
int fifo_read() |
总结
Above mainly IPC
made of a general introduction, and introduces signal (Signal) and duct two kinds of IPC
ways, both of which Linux
comes more functions implemented by the system. As Posix
and System V
inter-process communication message queues , signals , and shared memory , since the content more later reintroduced separately.