Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread vs Process  RSS feed

 
victor kamat
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A favorite interview question is:
What is the difference between Process and Thread.

Here is my answer:

Process:
An instance of a program;
Executed in own address space
Independent entity to which system assigns resources � CPU time, memory Cannot access variables or other data structure in another process Process communicate using inter-process mechanisms like files, pipes, sockets

Thread �
Is a particular execution path thru a process.
Multiple threads can share state info of a single process.
Thread share memory and system resources.
Can communicate thru shared variables and other memory structures
Context switching is faster than process.

Anyone care to add anything.
 
Jules Bach
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each process is an instance of at least one thread?
 
Maurizio Nagni
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to add my 5 cents....
For sure we agree that a Java class (as well a C++) containing a main method, starts a process but, at the same time, to make the main alive, the JVM starts a thread, eventually the father of all the next generated threads, right?
In this case, supposing a java/C++ application (it is for simplicty), thought as collection of N etherogeneous software, each one called throught a main method, can we affirm that the application can contains at least N process, that is, at least the number of main methods? In other words is a process the first thread to be created?
If so the difference between Process and Thread could be compared to a tree where the trunk (the main methods) and the branches (the thread) are "functionally" almost the same, if not that cutting the trunk will kill the whole process, but anatomically are just the same.
Do you agree?
 
victor kamat
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maurizio - While some of what you say is true, nonetheless the salient differences between a process and a thread are what I originally outlined.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!