Preface: Translation of horizontal slag, reading needs to be careful. There is a mistake to welcome correction.
What is the difference between a thread and a process?
What is the difference between threads and processes?
Processes vs Threads
Process vs Thread
A process is an executing instance of A application. What's does that mean? Well, for example, when you double-click the Microsoft Word icon, you start a process that runs Word. A thread is a path of execution within a process. Also, a process can contain multiple threads. When you start Word, the operating system creates a process and begins executing the primary thread of this process.
A process is an instance of an app, and this instance is in a running state. What does that mean? For example, when you double-click the Microsoft Word icon, you open a process that runs word. A process contains a thread, and of course it can contain multiple threads. When you run Word, the operating system creates a process and starts the main thread of the process.
It's important to note the a thread can do anything a process can do. But since a process can consist of multiple threads, a thread could is considered a ' lightweight ' process. Thus, the essential difference between a thread and a process is the work of each one are used to accomplish. Threads is used for small tasks, whereas processes is used for more ' heavyweight ' tasks–basically the execution of app Lications.
Note that threads can do things that any process can do. But consider that a large process can be composed of multiple threads, so a thread can be considered aLight weight-Level processes. Therefore, the key difference between threads and processes is that they are used to accomplish mission-like tasks. Threads are used to accomplish little people, and processes are more used for heavyweight tasks-basically the execution of an application.
Another difference between a thread and a process is that threads within the same process share the same address space, WH Ereas different processes do not. This allows threads to read from and write to the same data structures and variables, and also facilitates communication b Etween threads. Communication between processes–also known as IPC, or inter-process communication–is quite difficult and resource-inte Nsive.
Another difference between threads and processes is that threads of the same process share the same address space, but there is no such sharing between different processes. This allows the thread to read and write the same data structures, variables, and facilitate communication between threads. Process communication is also known as IPC (Inter process communication) and is rather difficult and resource-intensive.
Multithreading
Multithreading
Threads, of course, allow for multi-threading. A Common example of the advantage of multithreading are the fact that the can has a word processor that prints a document Using a background thread, but at the same time another thread is running this accepts user input, so that can type up A new document.
Of course, threads are not unique. A common example of multithreading advantage is that you can have your word processing tool use a background thread to print a document while another thread can accept the user's input so that you can type in a new document.
If we were dealing with a application that uses only one thread and then the application would is able to do one thing At a time–so printing and responding to user input at the same time would not being possible in a single threaded Applicati On.
If the app we're using uses only one thread, then the app will do one thing at a time-in a single-threaded application, it's impossible to print and respond to the user's input.
Each process has it's own address space, but the threads within the same process share that address space. Threads also share any other resources within that process. This means it's very easy-to-share data amongst threads, but it's also easy for the threads-step on each other, WH Ich can leads to bad things.
Each process has its own address space, but threads within the same process share the address space. Threads also share other resources within the process. This means that it's easy to share data between threads, but it's easy to thread each other (I think that's the interference between threads), which can lead to bad things happening.
Multithreaded programs must is carefully programmed to prevent those bad things from happening. Sections of code, modify data structures shared by multiple threads is called critical Sections. When a critical sections is running in one thread it's extremely important that no other thread being allowed into that critic Al section. This is called synchronization, which we wont get to any further over here. But, the multithreading requires careful programming.
In order to prevent bad things from happening, multithreaded programming must be careful. The code snippet that modifies a multithreaded shared data structure is called a critical section. When the critical section is running in one thread, it is important to ensure that no other threads are allowed to enter the critical section. This is called simultaneous sex and we won't go any further. However, the problem is that multithreading requires careful programming.
Also, context switching between threads is generally less expensive than in processes. And finally, the overhead (the cost of communication) between threads are very low relative to processes.
Context switching between threads is usually less costly than a context switch between processes. The burden of communication between threads is also very low relative to the process.
Here's a summary of the differences between threads and processes:
Here is a summary of the differences between processes and threads:
1. Threads is easier to create than processes since they
Don ' t require a separate address space.
1. Threads are easier to create than processes because the thread does not require a separate address space.
2. Multithreading requires careful programming since threads
Share data strucures that should is modified by one thread
At a time. Unlike threads, processes don ' t share the same
Address space.
Multithreading requires careful programming because the shared data structure should be modified only by one thread because of the thread-sharing structure.
3. Threads is considered lightweight because they use far
Less resources than processes.
3. Threads are considered lightweight because the line threads uses less resources than the process.
4. Processes is independent of each of the other. Threads, since they share the same address space is interdependent, so caution must is taken so this different Threads do N ' t step on each of the other.
This is really another the stating #2 above.
4. The process is independent of each other. Threads are internally interdependent because threads share the same address space. So be sure to be careful with the stampede between different threads.
5. A process can consist of multiple threads.
5. A process can consist of multiple threads.
Process:
Process:
An executing instance of a program is called a process.
Some operating systems use the term ' task ' to refer to a program, which is being executed.
An executable instance of an application is called a process. Some operating systems use terminology tasks to refer to programs that are being executed.
A process is all stored in the main memory also termed as the primary memory or random access memory.
Therefore, a process is termed as an active entity. It disappears if the machine is rebooted.
Several process may is associated with a same program.
On a multiprocessor system, multiple processes can is executed in parallel.
The process is always stored in main memory or RAM. Therefore, the process is referred to as an active entity. When the machine restarts, the process disappears. A program may be associated with more than one process. On multi-core processor systems, multiple processes can be executed in parallel.
On a uni-processor system, though true parallelism are not achieved, a process scheduling algorithm are applied and the proc Essor is scheduled to execute each of the process one at a time yielding an illusion of concurrency.
Example:executing multiple instances of the ' Calculator ' program. Each of the instances is termed as a process.
On a single-core system, although real parallelism is not possible, the process scheduling algorithm is used and the processor is dispatched to execute a process each time, creating the illusion of concurrency. For example: Executing multiple instances of a calculator, each instance being called a process.
Thread:
Thread:
A thread is a subset of the process.
It is termed as a ' lightweight process ', since it's similar to a real process but executes within the context of a proces S and shares the same resources allotted to the process by the kernel.
A thread is a subset of processes.
Threads are also known as lightweight processes because threads and real processes are similar, but execute in the context of a process and share resources allocated by the kernel to processes
Usually, a process has only one thread of control–one set of machine instructions executing at a time.
A process may also is made up to multiple threads of execution that execute instructions concurrently.
Multiple threads of control can exploit the true parallelism possible on multiprocessor systems.
On a uni-processor system, a thread scheduling algorithm is applied and the processor are scheduled to run each thread one At a time.
Typically, a process has only one thread control-one execution of a set of machine instructions at a time.
A process may have more than one thread to control, and these threads execute instructions concurrently.
Multithreading control makes true parallelism possible on multicore systems.
All the threads running within a process share the same address space, file descriptors, stack and other process related a Ttributes.
Since the threads of a process share the same memory, synchronizing the access to the shared data withing the process gain s unprecedented importance.
Threads that can run in the same process share the same address space, file descriptors, stacks, and other process-related properties.
Because the threads of a process share the same memory, it is never more important to synchronize access to shared data within the process.
More answers
Collated on 2015/8/2 Day
Thread VS Process from StackOverflow