Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a process and a thread?

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 threads. How about light-weight processes in languages like Erlang? Is there a definitive reason to use one term over the other?

like image 376
James Fassett Avatar asked Oct 14 '08 09:10

James Fassett


People also ask

What is a difference between process and thread with example?

Sharing Data: Different processes have different copies of data, files, and codes whereas threads share the same copy of data, file and code segments. Example: Opening a new browser (say Chrome, etc) is an example of creating a process. At this point, a new process will start to execute.

What is the difference between thread and process in Java?

Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creating a new process. Threads exist within a process — every process has at least one. Threads share the process's resources, including memory and open files.


1 Answers

Both processes and threads are independent sequences of execution. The typical difference is that threads (of the same process) run in a shared memory space, while processes run in separate memory spaces.

I'm not sure what "hardware" vs "software" threads you might be referring to. Threads are an operating environment feature, rather than a CPU feature (though the CPU typically has operations that make threads efficient).

Erlang uses the term "process" because it does not expose a shared-memory multiprogramming model. Calling them "threads" would imply that they have shared memory.

like image 117
Greg Hewgill Avatar answered Oct 09 '22 22:10

Greg Hewgill