I was asked this interview question. I replied that thread is the process after thinking that process is a superset of thread but interviewer didn't agree with it. It is confusing and I'm not able to find any clear answer to this.
-
Was the interviewer asking about PThreads in particular or about threads in general? – alk Jun 27 '14 at 17:21
-
@alk He was asking in general...does it matter ? – cbinder Jun 27 '14 at 17:48
-
1@cbinder-It won't matter for this question.Though I upvoted for this question because of the deeper context it carries,the usual answer is a simple one. Check my answer! – Am_I_Helpful Jun 27 '14 at 18:07
4 Answers
I feel like this is a terrible question.
- Both are independent blocks of execution
- Both are scheduled by the operating system
- Threads run within the context of a process, share memory with the process.
- I can't think of a time where a thread would have it's own address space
By that logic I would agree with your answer that a thread is a process. I think its kind of a loaded question. I would have asked you to explain the differences between the two.
For more information here's a good thread to view on the subject.
-
In general, not really. A process is an environment for an application instance, a thread is a unit of execution. A process without a thread cannot do anything, which is why the OS process loader raises one thread when a process initial working set has been loaded - to run code at its entry point. – Martin James Jun 28 '14 at 12:08
Every process is a thread, but not every thread is a process.
A thread is just an independet sequence of operations. A process has an additional context.

- 1,969
- 2
- 22
- 47
-
According to wiki " Multiple threads can exist within the same process and share resources such as memory, while different processes do not share these resource". So if two processes do not share resources how they can be threads from this definition .. ? – cbinder Jun 27 '14 at 18:00
-
Okay let's say a process contains at least one thread, so it's just the context for a number of threads? – thi gg Jun 27 '14 at 18:03
-
A process is an executing instance of an application.
A thread is a path of execution within a process.
Also, a process can contain multiple threads
.
1.
It’s important to note that a thread can do anything a process can do. But since a process can consist of multiple threads, a thread could be considered a ‘lightweight’ process. Thus, the essential difference between a thread and a process is the work that each one is used to accomplish. Threads are used for small tasks, whereas processes are used for more ‘heavyweight’ tasks – basically the execution of applications.
2.
Another difference between a thread and a process is that threads within the same process share the same address space, whereas different processes do not. This allows threads to read from and write to the same data structures and variables, and also facilitates communication between threads. Communication between processes – also known as IPC, or inter-process communication – is quite difficult and resource-intensive.

- 18,735
- 7
- 49
- 73
-
Hmm..you mean a thread is a lightweight process and we cant say directly about the one-to-one relation between them.. will take it as answer after getting a couple of responses supporting this..:) – cbinder Jun 27 '14 at 18:14
-
The nature of a thread is highly system dependent. For example, some systems implement threads as part of the operating system. Other system implement threads through a run-time library. The process itself manages its own threads (not the OS) and the management may be different for different processes (e.g., Java threading implemented differently from Ada threading).
In OS-scheduled threads, a thread and a process are different terms. A process is an address space with multiple, schedulable threads of execution.
In RTL-scheduled threads, the process is a thread.

- 20,574
- 3
- 26
- 62