0% found this document useful (0 votes)
40 views3 pages

Part4 0S

The document discusses threads and processes in operating systems. It covers topics like when to use threading vs processes, how threads share resources like memory but have private stacks, how kernel threads map to user threads, and differences between how Linux and Windows treat threads and processes.

Uploaded by

Thanh Đức
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

Part4 0S

The document discusses threads and processes in operating systems. It covers topics like when to use threading vs processes, how threads share resources like memory but have private stacks, how kernel threads map to user threads, and differences between how Linux and Windows treat threads and processes.

Uploaded by

Thanh Đức
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

OSG202 14/01

4.1

-Any kind of sequential program is not a good candidate to be threaded. An example of this is a program
that calculates an individual tax return. (2) Another example is a “shell” program such as the C-shell or
Korn shell. Such a program must closely monitor its own working space such as open files, environment
variables, and current working directory.

4.2

4.3

-Multi-threaded process threads share the (b) Heap memory and (c) Global variables. They have private
register values and stack segments.

4.4

- Output at LINE C is 5. Output at LINE P is 0.

4.5

a. The number of kernel threads allocated to the program is less than the number of processing cores.

-Some processes will be idle because the scheduler can only map kernel threads to processors – not user
level threads.

b. The number of kernel threads allocated to the program is equal to the number of processing cores.

-All processors may be used at the same time but a kernel thread blocking inside the kernel could cause
a processor to be idle.

c. The number of kernel threads allocated to the program is greater than the number of processing

cores but less than the number of user-level threads.

-A blocked kernel thread here can be swapped for another that is available and ready

4.7
4.8

4.9

No. The kernel is not aware of the user-level threads that are created. Therefore, it is not able to run the
user-level threads on different processors.

4.10

When a thread is created the threads does not require any new resources to execute the thread shares
the resources like memory of the process to which they belong to. The benefit of code sharing is that it
allows an application to have several different threads of activity all within the same address space.
Whereas if a new process creation is very heavyweight because it always requires new address space to
be created and even if they share the memory then the inter process communication is expensive when
compared to the communication between the threads.

4.11

When a kernel thread suffers a page fault, another kernel thread can be switched in to use the
interleaving time in a useful manner. A single-threaded process, on the other hand, will not be capable
of performing useful work when a page fault takes place. Therefore, in scenarios where a program might
suffer from frequent page faults or has to wait for other system events, a multi-threaded solution would
perform better even on a single-processor system.

4.14

-Linux operating systems consider both threads and processes as tasks; it cannot distinguish between
them. In contrast, windows operating system threads and processes differently.

This approach has pros and cons while modeling threads and processes inside the kernel.

-Pros:

Linux consider this as similar, so codes belong to operating system can be cut down easily.

Scheduler present in the Linux operating systems do not need special code to test threads coupled with
each processes.

It considers different threads and processes as a single task during the time of scheduling.

-Cons:

- This ability makes it harder for the Linux operating system to inflict process-wide resource limitations
directly.

- Extra steps are needed to recognize the each processes belong to appropriate threads and complexity
in performing relevant tasks.

4.15
Context switching between user threads is quite similar to switching between kernel threads, although it
is dependent on the threads library and how it maps user threads to kernel threads. In general, context
switching between user threads involves taking a user thread of its LWP and replacing it with another
thread. This act typically involves saving and restoring the state of the registers

You might also like