Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between lightweight process and thread?

I found an answer to the question here. But I don't understand some ideas in the answer. For instance, lightweight process is said to share its logical address space with other processes. What does it mean? I can understand the same situation with 2 threads: both of them share one address space, so both of them can read any variables from bss segment (for example). But we've got a lot of different processes with different bss sections, and I don't know, how to share all of them.

like image 656
Allok Avatar asked May 07 '12 15:05

Allok


People also ask

Is thread a lightweight process?

Threads are sometimes called lightweight processes because they have their own stack but can access shared data. Because threads share the same address space as the process and other threads within the process, the operational cost of communication between the threads is low, which is an advantage.

What is the difference between a regular process and a light weight process?

The main difference between a light weight process (LWP) and a normal process is that LWPs share same address space and other resources like open files etc.

What is the difference between a process and a thread?

A process is a program under execution i.e an active program. A thread is a lightweight process that can be managed independently by a scheduler. Processes require more time for context switching as they are more heavy. Threads require less time for context switching as they are lighter than processes.

What is meant by lightweight process?

Lightweight processes (LWPs) bridge the user level and the kernel level. Each process contains one or more LWP, each of which runs one or more user threads. (See Figure 1-1.) The creation of a thread usually involves just the creation of some user context, but not the creation of an LWP.


1 Answers

I am not sure that answers are correct here, so let me post my version.

There is a difference between process - LWP (lightweight process) and user thread. I will leave process definition aside since that's more or less known and focus on LWP vs user threads. LWP is what essentially are called today threads. Originally, user thread meant a thread that is managed by the application itself and the kernel does not know anything about it. LWP, on the other hand, is a unit of scheduling and execution by the kernel.

Example: Let's assume that system has 3 other processes running and scheduling is round-robin without priorities. And you have 1 processor/core.

Option 1. You have 2 user threads using one LWP. That means that from OS perspective you have ONE scheduling unit. Totally there are 4 LWP running (3 others + 1 yours). Your LWP gets 1/4 of total CPU time and since you have 2 user threads, each of them gets 1/8 of total CPU time (depends on your implementation)

Option2. You have 2 LWP. From OS perspective, you have TWO scheduling units. Totally there are 5 LWP running. Your LWP gets 1/5 of total CPU time EACH and your application get's 2/5 of CPU.

Another rough difference - LWP has pid (process id), user threads do not.

For some reason, naming got little messed and we refer to LWP as threads.

There are definitely more differences, but please, refer to slides. http://www.cosc.brocku.ca/Offerings/4P13/slides/threads.ppt

EDIT:

After posting, I found a good article that explains everything in more details and is in better English than I write. http://www.thegeekstuff.com/2013/11/linux-process-and-threads/

like image 167
Tigran Avatar answered Sep 20 '22 12:09

Tigran