What is the difference between a process and a thread?

后端 未结 30 2213
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:18

    From the point of view of an interviewer, there are basically just 3 main things that I want to hear, besides obvious things like a process can have multiple threads:

    1. Threads share same memory space, which means a thread can access memory from other's thread memory. Processes normally can not.
    2. Resources. Resources (memory, handles, sockets, etc) are release at process termination, not thread termination.
    3. Security. A process has a fixed security token. A thread, on the other hand, can impersonate different users/tokens.

    If you want more, Scott Langham's response pretty much covers everything. All these are from the perspective of an operating system. Different languages can implement different concepts, like tasks, light-wigh threads and so on, but they are just ways of using threads (of fibers on Windows). There are no hardware and software threads. There are hardware and software exceptions and interrupts, or user-mode and kernel threads.

提交回复
热议问题