Difference between Thread and Process

Hi!

I was googling about this subject, and I found this old thread on google: [url]http://forum.java.sun.com/thread.jspa?threadID=580508&messageID=2939031[/url]

My specific doubt is: can one thread inside in a process affect other thread inside in other process?

But, actually, the terms thread and process are not clear for me yet. I don't know what is the exact difference yet.

[409 byte] By [Marcelo9a] at [2007-10-2 7:33:05]
# 1

> My specific doubt is: can one thread inside in a

> process affect other thread inside in other process?

Indirectly, yes - if those threads are communicating somehow (via a socket, file, etc).

> But, actually, the terms thread and process are not

> clear for me yet. I don't know what is the exact

> difference yet.

A process contains one or more threads of execution. Threads may execute concurrently (in the case of a multi-processor machine with a different processor executing one thread versus another) or interleaved (in the case of the same processor executing instructions of different threads).

Somehow I doubt this clears your doubt.

warnerjaa at 2007-7-16 21:13:15 > top of Java-index,Java Essentials,Java Programming...
# 2

> > My specific doubt is: can one thread inside in a

> > process affect other thread inside in other

> process?

> Indirectly, yes - if those threads are communicating

> somehow (via a socket, file, etc).

> > But, actually, the terms thread and process are

> not

> > clear for me yet. I don't know what is the exact

> > difference yet.

> A process contains one or more threads of execution.

> Threads may execute concurrently (in the case of a

> multi-processor machine with a different processor

> executing one thread versus another) or interleaved

> (in the case of the same processor executing

> instructions of different threads).

>

> Somehow I doubt this clears your doubt.

Yeah, unfortunatelly, I have doubts yet. But, thanks, anyway. I need to search more about this topic!

Marcelo9a at 2007-7-16 21:13:15 > top of Java-index,Java Essentials,Java Programming...
# 3

If I start a JVM, and Microsoft Word, and a web browser, that's three processes. A process is an OS-level construct.

Threads refer to concurrent execution paths within a given process. Just like multiple processes can run in parallel within the OS, so can multiple threads run in parallel within a process.

Now, to confuse matters somewhat, on some OSes, multiple threads within one process may be implemented as lightweight processes, so that the ps command or task manager or whatever might show multiple instances of the same executable. I'm not sure of the details of a lightweight process vs. a normal one, but I think one key thing is that the various lightweight processes share the same memory space as the parent that spawned them.

jverda at 2007-7-16 21:13:15 > top of Java-index,Java Essentials,Java Programming...
# 4

> If I start a JVM, and Microsoft Word, and a web

> browser, that's three processes. A process is an

> OS-level construct.

>

> Threads refer to concurrent execution paths within a

> given process. Just like multiple processes can run

> in parallel within the OS, so can multiple threads

> run in parallel within a process.

That's exactly what I understood. So, I suppose that a thread in a process cannot affect other thread in other process, can it? I mean, the wait( ), notify( ), etc, methods do not make sense if you consider threads of different process, right?

> Now, to confuse matters somewhat, on some OSes,

> multiple threads within one process may be

> implemented as lightweight processes, so that

> the ps command or task manager or whatever might show

> multiple instances of the same executable. I'm not

> sure of the details of a lightweight process vs. a

> normal one, but I think one key thing is that the

> various lightweight processes share the same memory

> space as the parent that spawned them.

Indeed, very confusing. They could facilitate, defining a clear distinction between thread and process.

Marcelo9a at 2007-7-16 21:13:15 > top of Java-index,Java Essentials,Java Programming...
# 5
> various lightweight processes share the same memory> space as the parent that spawned them.Could very well be.The difference between thread and process is process = Threads + memory.
tjacobs01a at 2007-7-16 21:13:15 > top of Java-index,Java Essentials,Java Programming...
# 6

> > If I start a JVM, and Microsoft Word, and a web

> > browser, that's three processes. A process is an

> > OS-level construct.

> >

> > Threads refer to concurrent execution paths within

> a

> > given process. Just like multiple processes can

> run

> > in parallel within the OS, so can multiple threads

> > run in parallel within a process.

>

> That's exactly what I understood. So, I suppose that

> a thread in a process cannot affect other thread in

> other process, can it?

Not at the Java language level.

> I mean, the wait( ), notify(

> ), etc, methods do not make sense if you consider

> threads of different process, right?

Right. Those are just methods that you call on objects. The same rules apply to them as to other methods. Now, with RMI, it might be possible to call wait(), etc. on a remote object. I've never use RMI, but I don't think that actually works. If it does, I expect it would be in an RMI tutorial.

> Indeed, very confusing. They could facilitate,

> defining a clear distinction between thread and

> process.

Well, there is a distinction in their "interface," if you will. It's just that their implementations can overlap.

Kind of like how a List and a Set are different, but you could implement a Set by composing it with a List.

jverda at 2007-7-16 21:13:15 > top of Java-index,Java Essentials,Java Programming...
# 7
Thank you, for all these explanations!
Marcelo9a at 2007-7-16 21:13:15 > top of Java-index,Java Essentials,Java Programming...
# 8
A process has its own memory space, stack and id, while a thread would run within a process additionaly a thread might have to share the process resources(its running in) with other threads.Both the terms are however used interchangibly that might be incorrect though but still....
kilyasa at 2007-7-16 21:13:15 > top of Java-index,Java Essentials,Java Programming...