views:

66

answers:

3

What is the diff. between a thread/process/task?

A: 

Wikipedia sums it up quite nicely:

Threads compared with processes

Threads differ from traditional multitasking operating system processes in that:

  • processes are typically independent, while threads exist as subsets of a process
  • processes carry considerable state information, whereas multiple threads within a process share state as well as memory and other resources
  • processes have separate address spaces, whereas threads share their address space
  • processes interact only through system-provided inter-process communication mechanisms.
  • Context switching between threads in the same process is typically faster than context switching between processes.

Systems like Windows NT and OS/2 are said to have "cheap" threads and "expensive" processes; in other operating systems there is not so great a difference except the cost of address space switch which implies a TLB flush.

Task and process are used synonymously.

Loxley
+2  A: 

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.

Rodrick Chapman
+1  A: 

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 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.

Task:

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

billu
comments are welcome for my first answer in StackOverflow
billu
Process and threads are related but otherwise orthogonal concepts. A thread is what the CPU actually runs; it's about scheduling access to shared resources (e.g. the CPU). A process is the allocated memory for instructions and data (a process needs memory for code and data). Of course a process will need one or more threads b/c that is what is actually run by the CPU. Multiple threads just means that the process gets more time slices on the same CPU or get to run on more CPUs concurrently. Think of a thread as a slice of time and a process as a slice of space (a region of memory in this case).
Rodrick Chapman