PROCESS vs THREAD
PROCESS
A process will execute the threads(set of instructions), which may contain multiple threads sometimes.
THREAD
It contains a group of instructions that a processor has to do.
Difference
In a nutshell, a process can contain multiple threads.
A process, in the simplest terms, is an executing program. One or more threads run in the context of the process. A thread is the basic unit to which the operating system allocates processor time. A thread can execute any part of the process code, including parts currently being executed by another thread. A fiber is a unit of execution that must be manually scheduled by the application. Fibers run in the context of the threads that schedule them.
In most multithreading operating systems, a process gets its own memory address space; a thread doesn't. Threads typically share the heap belonging to their parent process.
For instance, a JVM runs in a single process in the host O/S. Threads in the JVM share the heap belonging to that process; that's why several threads may access the same object.
Typically, even though they share a common heap, threads have their own stack space. This is how one thread's invocation of a method is kept separate from another's.
This is all a gross oversimplification, but it's accurate enough at a high level. Lots of details differ between operating systems.
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 ata 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 onr another and process might or not might be assisted on one another.
thread is nothing but flow of execution where as process is nothing but a group of instructions which is similar to that of a program except which may be stopped and started by the os itself
1. Different processes can't work under same memory location. They have their own individual working memory segment. But the threads can work under the same memory area. Even they can access any memory location.
2. Processes have the overhead of making all the work within it orderly and also sum up them. But threads are done for a single unit of task only and at completion their work is all over.
3. Multiple processes require the resources explicitly to work with. They are least concerned about sharing them. i.e why when a system implements a multi process system it is expensive as compared to multi-threaded system. Because the threads have good strategy to share the things.
4.One process can run on more than one thread.
For this answer you require knowledge of Linux kernel. In Linux O/S, process is a program in execution. Two processes can share text (code) section (In case of fork() call), but sharing of data section of the processes is not possible. Prior to Linux kernel 2.0, POSIX thread library was used in only user space. So multi threaded applications using p_thread library were seen by the kernel as a part of single process. Threads can share the heap part but not the stack part. Scheduling, resource management etc of all those multi threaded application took place in user's address space. After Kernel 2.4, concept of lightweight process was implemented, in which 2 LWPs can share address space, open files etc. So now attaching threads using p_thread library with LWPs, real multi threading is visible to the kernel. So there is difference between a process, LWP and thread in Linux.
Don't look at kernel level. Think of a process as a set of tasks. but the problem arise when two or more tasks are to be performed concurrently, because a process which contain exact one thread can't perform concurrent task. So to divide task, in sets so they can be performed independently to each other, mechanism of threading is used. by default a process contain exact one thread. if the process is multi threaded than that process can perform many task simultaneously. for example take a editor program; that�s nothing but a process; process of editing a file. This editing process contain many task like typing (editing), saving, printing�. Ok. Suppose process is automated and it takes input from user, it save that input in file automatically and it print file automatically�. Ok If process contains only one thread then while you edit process can�t save your typing. It can save file only when you stopped editing. And also it can�t print when you type� only one task is done. But, if it contains 3 threads. 1st thread given task of saving and 2nd thread given task of printing. File will be automatically saved while you are typing, you won�t have to stop editing to save file. and same as 3rd thread can print your editing while you are typing. All the three tasks can be performed simultaneously.
Consider a very simple database server running on a computer.
This server is a process. Now if the process was single threaded, then there would only be one point of execution. This would mean that only one client could connect to the database at a time. Any other clients would have to wait, unless multiple processes were created, for each client - this could have quite a large overhead.
A more realistic database would be multi-threaded. One database server 'process' would be running. For each client which connects to the database a thread, (or point of execution) would be created. In this way, many clients could connect, using a thread to interact with the database.
A process is a term used to describe the execution of a sequential program. A thread is a point of execution within the process.
Early computers were dedicated mainframes used for a single purpose and handled by a single group of people or a closely related group of people. The programs that ran on these systems were also developed by a related group of people. Everyone knew what kind of program was in use and also the limitations of this program. Even if this program was run concurrently all the concurrent instances of execution could share the same memory. This was fine as long as there was only a single dedicated program running. Later people started using a computer for a variety of computational tasks all running at the same time. (Like one program might be listing the number of records that are stored while another program might be computing how many users had accessed these stored records.) Now both the programs might have been written by two different groups of people. There is a risk that the second program might crash the first one. Hence an idea was proposed that each program 'thread' will have its own working space or memory which the other programs cannot access. Such an independent execution of a program came to be known as a 'process'. This could be contrasted with multiple instances of the same program that share the single working space or memory and retained the name 'thread'.
A process a collection of virtual memory space, code, data, and system resources. A thread is code that is to be serially executed within a process. A processor executes threads, not processes.
The basic difference between process and thread is every process have its own data memory location but all related threads can share same data memory and have their own individual stacks.
Thread is a light weighted process,collection of threads become process.
Multi Processes can share the resources by using IPC objects. When a process accessing the resource the codex switching(from user mode to kernel mode)is required, that increases the execution time.
But in case of multi threads,while sharing the resources the thread always run in user mode only,i.e context switching is not required.Then it reduces the execution time.
Thread is light weight process having its own stack but collection of related threads can share same execution memory.process is program or part of program under execution .every process can have its own execution environment.
Thread is a light weight process or a sub-process. In fact a thread is also a kind of process. Thread can not exist by itself, a "process" has to start a "thread". A process can start multiple threads.
Below are the links for best material and presentations on PROCESS and THREAD DOWNLOAD THEM ............
Posted at 23:26 | Labels: operating systems, os |
0 comments:
Post a Comment