On Wed, 19 Mar 2003 08:24:12 +0000
John Lamb
Rohit wrote:
What is the difference between a process and a thread - except for I know that a process has a unique PID associated with it..
Processes are entirely separate, though they may communicate. Many applications fork processes when they want to do two things at once. For example, an application could use one process to run a clock and another to edit a file. Threads are separate sequences of execution within the same code. So two threads within the same process share global variables but not local variables.
Threads are better for some applications. For example, an SQL server can use separate threads to handle separate requests while still maintaining easy access to lock information in global variables. While one thread is waiting for resources another can still execute.
On a practical note, threaded apps still get a pid for each thread under linux, but when you view them with top, their name appears as "3". So it is useful to use the "c" option for top to see the real name of threads. I put a alias in .bashrc alias top='top c' -- use Perl; #powerful programmable prestidigitation