Saturday, January 5, 2008

工作笔试(三)What isthe difference between a ‘thread’ and a ‘process’?

Ans.

1. A process is a collection of virtual memory space, code, data, and system resources. A thread is code that is to be serially executed within a process.

2. A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary thread. A process can have multiple threads in addition to the primary thread. Prior to the introduction of multiple threads of execution, applications were all designed to run on a single thread of execution.

3. When a thread begins to execute, it continues until it is killed or until it is interrupted by a thread with higher priority (by a user action or the kernel’s thread scheduler).

4. Each thread can run separate sections of code, or multiple threads can execute the same section of code. Threads executing the same block of code maintain separate stacks. Each thread in a process shares that process’s global variables and resources.

-----------------------------------------------------------------------
Ans.

process is a execution of a program and program contain set of instructions but thread is a single sequence stream within the process. thread is sometime called lightweight process. single thread alows a os to perform singler task at a time.

similarities between process and threads are: 1)share cpu. 2)sequential execution 3)create child??? 4)if one thread is blocked then the next will be start to run like process???.

dissimilarities: 1)threads are not independent like process. 2)all threads can access every address in the task unlike process. 3)threads are design to assist one another and process might or not might be assisted on one another.

0 comments: