Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a thread/process/task?

What is the difference between a thread/process/task?

like image 474
billu Avatar asked Jun 15 '10 05:06

billu


People also ask

What is difference between task and process?

Tasks are made up of actions or steps. A process is an upper level description of a series of major steps required to accomplish an objective. Processes are generally made up of procedures or tasks. A task is another way of describing a procedure.

Should I use task or thread?

It is always advised to use tasks instead of thread as it is created on the thread pool which has already system created threads to improve the performance. The task can return a result. There is no direct mechanism to return the result from a thread.

What is the difference between thread and task in RTOS?

The threads within a process have their own context, exactly the same as task in the RTOS. The difference being that a thread is running in a virtual address space, whereas a task runs in a physical one.

What is a process and a thread?

A process, in the simplest terms, is an executing program. One or more threads run in the context of the process. A thread is the basic unit to which the operating system allocates processor time. A thread can execute any part of the process code, including parts currently being executed by another thread.


2 Answers

Process:

A process is an instance of a computer program that is being executed. It contains the program code and its current activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently. Process-based multitasking enables you to run the Java compiler at the same time that you are using a text editor. In employing multiple processes with a single CPU,context switching between various memory context is used. Each process has a complete set of its own variables.

Thread:

A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set of registers. A thread of execution results from a fork of a computer program into two or more concurrently running tasks. The implementation of threads and processes differs from one operating system to another, but in most cases, a thread is contained inside a process. Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resources. Example of threads in same process is automatic spell check and automatic saving of a file while writing. Threads are basically processes that run in the same memory context. Threads may share the same data while execution. Thread Diagram i.e. single thread vs multiple threads

Task:

A task is a set of program instructions that are loaded in memory.

like image 97
billu Avatar answered Oct 09 '22 19:10

billu


Short answer:

A thread is a scheduling concept, it's what the CPU actually 'runs' (you don't run a process). A process needs at least one thread that the CPU/OS executes.

A process is data organizational concept. Resources (e.g. memory for holding state, allowed address space, etc) are allocated for a process.

like image 44
Rodrick Chapman Avatar answered Oct 09 '22 17:10

Rodrick Chapman