IPC (interprocess communication) on the linux

Linux under inter-process communication of the main ways

  1. Pipes (Pipe) and named pipes (named pipe): pipes can be used to have communication between the kinship process, named pipes to overcome the limitations pipeline with no name, therefore, in addition to a pipe with the functions, it also allows unrelated inter-process communication;
  2. Signal (Signal): the signal is more complex communication mode for receiving the notification process has some event occurs, except for inter-process communication, the process can also send a signal to the process itself; Linux early signal Unix semantics in addition to supporting function sigal but also support signal sigaction function semantics conform Posix.1 standard (in fact, the function is based on the BSD, BSD order to achieve reliable signal mechanism, but also to unify external interface, use sigaction function to re-implement the signal function);
  3. Message (Message) queue (message queue): message queue table is linked message, comprising the message queue Posix system V message queue. Has sufficient rights process can add a message to the queue, was given permission to read a process you can go read messages in the queue. Signal bearing the message queue overcome small amount of information, only the carrier pipe plain byte stream buffer size is limited, and other shortcomings.
  4. Shared Memory: allows multiple processes can access the same memory space, is the fastest form of IPC available. For other communication mechanism is not efficient design. Often, such as semaphores in conjunction with other communication mechanism, to achieve synchronization and mutual exclusion between processes.
  5. Semaphore (semaphore): mainly as a means of inter-process synchronization as well as between the different threads in the same process.
  6. Socket (Socket): more general inter-process communication mechanism can be used for inter-process communication between the different machines. It was originally developed by BSD Unix systems branch out, but they are generally portable to other Unix-like systems: Linux and System V variants support sockets.

The difference between multi-threaded and multi-process

  • Process: a dynamic process of program execution.
  • Thread: dispatch unit of executable code.
  • Multi-process: linux, a process created by fork function to create child process will be complete copy of the parent process task_struct structure and assign physical pages to stack the child process. Obviously, I can simply understood as the process of creating a replication process.
  • Multithreading: linux, if we put a process likened to a river, then a lot of these rivers slicing small pieces of river sections can be considered one of the threads. In the thread-based multitasking environment, all processes have at least one thread, but they can have multiple tasks. This means that a single program can perform two or more tasks concurrently to achieve concurrent execution.
  • Multi-process and multi-threaded compared: First of all, multi-process will have higher overhead than multithreading, we can divide the copy from the river and the river cut this view up to know. Multi-threaded multi-process better than in the case of large CPU-intensive operations. Of course, since multiple threads belong to the same process, so direct and shared memory addresses between them, but for multi-process, it is necessary for data transfer through a particular way. Process for improving the performance of the system is theoretically no limit, as long as there is strong enough CPU and memory creation, the process is not affected. But for multithreading, his system performance improvement is limited, after reaching a certain limit value, even in a thread is created, not only does not improve performance, but may reduce the performance of the entire system, simultaneous multithreading solo The same number will also bring some problems to the CPU scheduling.
  • Characterization:

  • Advantages and disadvantages:

 

Guess you like

Origin www.cnblogs.com/lijiahaoAA/p/10960240.html