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

Threads vs. processes  RSS feed

 
Leena Diwan
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was asked..
what is the diff between a thread and a process ?
can anyone help ?
Thanks in advance..
Greetings..
Leena
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A thread shares its memory space with all other threads living inside the same process. On one hand, this makes it easy for threads to interact with each other as they can simply share data (objects). On the other, if a thread crashes badly it can easily take all other threads down with it. Because threads share so many resources with other threads inside the same process, they are relatively lightweight.
A process is isolated as much as possible from other processes by the operating system. In particular processes cannot access each others' memory (although there exists a shared memory facility through which processes can share data). Each process has its owner, security permissions, etc. Processes are considered heavyweight because they are generally expensive to create.
- Peter
[ April 07, 2002: Message edited by: Peter den Haan ]
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way to look at it is that a process is a set of code and resources. A thread is something which is running at some point in that code using those resources. You can have multiple threads running within a process.
For instance, if you considered a book a process, a thread would be the person reading it. And several different people could read from the same book at the same time.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like your analogy Welcome back, CLG.
- Peter
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!