What is the difference between a process and a thread?

后端 未结 30 2146
Happy的楠姐
Happy的楠姐 2020-11-22 00:39

What is the technical difference between a process and a thread?

I get the feeling a word like \'process\' is overused and there are also hardware and software threa

相关标签:
30条回答
  • 2020-11-22 01:11
    1. Basically, a thread is a part of a process without process thread wouldn't able to work.
    2. A thread is lightweight whereas the process is heavyweight.
    3. communication between process requires some Time whereas thread requires less time.
    4. Threads can share the same memory area whereas process lives in separate.
    0 讨论(0)
  • 2020-11-22 01:12

    A process is a collection of code, memory, data and other resources. A thread is a sequence of code that is executed within the scope of the process. You can (usually) have multiple threads executing concurrently within the same process.

    0 讨论(0)
  • 2020-11-22 01:12

    They are almost as same... But the key difference is a thread is lightweight and a process is heavy-weight in terms of context switching, work load and so on.

    0 讨论(0)
  • 2020-11-22 01:13
    • Every process is a thread (primary thread).
    • But every thread is not a process. It is a part(entity) of a process.
    0 讨论(0)
  • 2020-11-22 01:13

    Example 1: A JVM runs in a single process and threads in a JVM share the heap belonging to that process. That is why several threads may access the same object. Threads share the heap and have their own stack space. This is how one thread’s invocation of a method and its local variables are kept thread safe from other threads. But the heap is not thread-safe and must be synchronized for thread safety.

    0 讨论(0)
  • 2020-11-22 01:14

    I've perused almost all answers there, alas, as an undergraduate student taking OS course currently I can't comprehend thoroughly the two concepts. I mean most of guys read from some OS books the differences i.e. threads are able to access to global variables in the transaction unit since they make use of their process' address space. Yet, the newly question arises why there are processes, cognizantly we know already threads are more lightweight vis-à-vis processes. Let's glance at the following example by making use of the image excerpted from one of the prior answers,

    We have 3 threads working at once on a word document e.g. Libre Office. The first does spellchecking by underlining if the word is misspelt. The second takes and prints letters from keyboard. And the last does save document in every short times not to lose the document worked at if something goes wrong. In this case, the 3 threads cannot be 3 processes since they share a common memory which is the address space of their process and thus all have access to the document being edited. So, the road is the word document along with two bulldozers which are the threads though one of them is lack in the image.

    0 讨论(0)
提交回复
热议问题