Operating system--processes and threads

Source: Internet
Author: User

the difference between threads and processes

1) Dispatch: In the traditional operating system, the basic unit with resources and the basic unit of independent Dispatch and dispatch are all processes.

While the threading operating system is introduced, the thread is used as the basic unit of dispatch and dispatch, and the process as the basic unit of the resource.

2) Concurrency: In an operating system that introduces threads, processes can be executed concurrently, and multiple threads in one process can execute concurrently.

3) Having resources: processes can have resources and are a basic unit of resources in the system.

The thread itself does not own system resources, but it can access resources for its subordinate processes.

4) Overhead: The cost of operating system is significantly greater than the cost of thread creation or revocation, and the switching cost of the process is much higher than the thread.

  The change of thread only represents a change in the CPU execution process, without the resource changes that the process has.

a process has a complete virtual address space that is independent of the thread, and vice versa, a thread is part of a process that does not have its own address space and shares all the resources assigned to the process with other threads in the process .

Inter-process communication methods
    • There are also named pipes and non-named pipes in the pipeline, non-named pipes can only be used for parent-child process communication, named pipes can be used for non-parent-child processes, named Pipes are FIFO, pipelines are first-out communication. FIFO is a first-in-one-out queue. It is similar to a pipeline that allows only one-way flow of data. Each FIFO has a name that allows unrelated processes to access the same FIFO and therefore also becomes a named tube.
    • Message Queuing: is used for communication between two processes, first creating a message queue in one process, then writing the data to the message queue, and the other process fetching data from that message queue. Note that Message Queuing is created by creating a file, and if one process writes data to a message queue, the other process does not take out the data, even though the process of writing data to the message queue has ended, the data saved in the message queue does not disappear. That is, the next time from this message queue to read data, is the last data!!!
    • Semaphore, cannot transmit complex messages, can only be used to synchronize
    • Shared memory, as long as a shared memory area is created first, other processes can access the data in this shared memory area according to certain steps, which is readable and writable;

Several ways to compare:

    • Piping: slow speed, limited capacity
    • Message Queuing: The capacity is limited by the system, and the first time you read it, consider the last time you did not read the data.
    • Semaphore: Cannot pass complex message, can only be used to synchronize
    • Shared memory Area: can easily control capacity, fast, but to maintain synchronization, such as when a process in writing, another process to pay attention to read and write issues, the equivalent of thread security threads, of course, the shared memory area can also be used for inter-thread communication, but without this need, the thread has already shared a piece of memory.

Operating system--processes and threads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.