What is the difference between plug and flow?

Can someone explain the difference between plug and stream?

+79
c multithreading process fork
Mar 20
source share
5 answers

The fork gives you a whole new process, which is a copy of the current process with the same code segments. As the memory image changes (as a rule, this is due to the different behavior of the two processes), you get a separation of the memory images (Copy On Write), but the executable code remains unchanged. Tasks do not share memory unless they use the Inter Process Communication (IPC) primitive.

One process can have several threads, each of which runs in parallel in the same process context. Memory and other resources are distributed between threads, so access to shared data should be through some primitive and synchronization objects (for example, mutexes , condition variables, and semaphores ), which help to avoid data corruption.

+72
Mar 20 '10 at 12:53
source share

Fork:

Fork is nothing more than a new process that looks exactly like the old or parent process, but still it is a different process with a different process identifier and having its own memory. The parent process creates a separate address space for the child. Both the parent and the child processes have the same code segment, but are executed independently of each other.

The simplest example of forcing is when you run a command on a shell in unix / linux. Each time the user issues a command, the shell wags the child process and the task is completed.

When the fork system call is issued, a copy of all pages corresponding to the parent process is created, loaded into a separate OS memory location for the child process, but in some cases this is not required. As with the 'exec system calls, there is no need to copy the parent pages of the process, because execv replaces the address space of the parent process itself.

A few things that you should pay attention to forking are:

  • The child process will have its own unique process identifier.
  • The child process must have its own copy of the parent file descriptor.
  • File locks set by the parent process must not be inherited by the child process.
  • Any semaphores open in the parent process must also be open in the child process.
  • The child process must have its own copy of the parent's message queue descriptors.
  • The child will have its own address space and memory.

Topics:

Threads are light weight processes (LWP). Traditionally, a thread is simply a state of the CPU (and some other minimal state) with a process containing remains (data, stack, I / O, signals). Threads require less overhead than forking or spawn a new process because the system does not initialize the new system virtual memory space and process environment. Although most effective in a multiprocessor system where a process flow can be scheduled to run on another processor, thereby gaining speed through parallel or distributed processing, gains are also found in single-processor systems that use latency in I / O and other system functions that can stop process execution.

Threads of the same process resource:

  • Process instructions
  • Most data
  • open files (descriptors)
  • signals and signal handlers
  • current working directory
  • User id and group

More information can be found here .

+61
Jan 13 '13 at 15:23
source share

The answer to Dacav is excellent, I just wanted to add that not all streaming models give you true multiprocessing.

For example, Ruby's default streaming implementation does not use true OS / kernel threads. Instead, it simulates multiple threads by switching between Thread objects within the same thread / kernel process.

This is important for multiprocessor / multi-core systems, because these types of lightweight threads can only work on one core - you are not able to significantly improve performance when there are multiple threads.

Elsewhere, it matters when one thread blocks (awaits I / O or calls the IOCTL driver) all Threads blocks.

This is currently not very common: most streaming implementations use kernel threads that do not suffer from these problems, but their value for completeness.

In contrast, fork provides you with another process that runs simultaneously on a different physical processor when the original process runs. Some people find IPC more suitable for their application, others prefer streams.

Good luck and have fun! Multithreading is both complex and useful.

+26
Mar 20 '10 at 14:24
source share

Themes are functions that are executed in parallel, fork is a new process with parental inheritance. Themes are good for completing a task in parallel, and forks is an independent process that also runs simultaneously. Themes have race conditions and control semaphores and locks or mutexes, pipes can be used both in the plug and in the stream.

+5
Aug 03 2018-12-12T00:
source share
  • Themes share the address space of the process that created it; processes have their own address space.
  • Topics have direct access to the data segment of his process; processes have their own copy of the data segment of the parent process.
  • Themes can interact directly with other threads of their process; processes must use interprocess communication to communicate with kinship processes.
  • There is almost no overhead in flows; processes have significant overhead.
  • New threads are easy to create; new processes require duplication of the parent process.
  • Threads can exercise significant control over threads of the same process; processes can exercise control over child processes.
  • Changes to the main thread (cancellation, change of priority, etc.) can affect the behavior of another process thread; changes to the parent process do not affect child processes.
+4
Jul 20 '14 at 14:28
source share



All Articles