Sei sulla pagina 1di 3

TSN2101

– Tutorial 3 (Processes and Threads)

1. What are the process elements in a process control block (PCB)?

Solution:

At any given point in time, while a process in execution, this process can be uniquely characterized by a
number of elements that are known as process elements. They are given as follows:

§ Identifier: A unique identifier associated with this process, to distinguish it from all other processes.
§ State: If the process is currently executing, it is in the running state.
§ Priority: Priority Level relative to other processes.
§ Program counter: The address of the next instruction in the program to be executed.
§ Memory pointers: Includes pointers to the program code and data associated with this process, plus
any memory blocks shared with other processes.
§ Context data: These are data that are present in registers in the processor while the process is
executing.
§ I/O status information: Includes outstanding I/O requests, I/O devices (e.g., tape drives ) assigned to
this process, a list of files in use by the process, and so on.
§ Accounting information: May include the amount of processor time and clock time used, time limits,
account numbers, and so on.

2. Draw the process state diagram depicting the five states that a process can be in.

Solution:

• New: The process is being created.


• Running: Instructions are being executed.
• Waiting: The process is waiting for some event to occur.
• Ready: The process is waiting to be assigned to a process.
• Terminated: The process has finished execution.

3. Describe the actions taken by a kernel to context-switch between processes.

Solution:

In general, the operating system must save the state of the currently running process and restore the
state of the process scheduled to be run next. Saving the state of a process typically includes the values of
all the CPU registers in addition to memory allocation. Context switches must also perform many
architecture-specific operations, including flushing data and instruction caches.

4. Describe the differences among short-term, medium-term, and long term scheduling.

Solution:

§ Short-term (CPU scheduler): selects from jobs in memory those jobs that are ready to execute and
allocates the CPU to them.
§ Medium-term: used especially with time-sharing systems as an intermediate scheduling level. A
swapping scheme is implemented to remove partially run programs from memory and reinstate them
later to continue where they left off.
§ Long-term (job scheduler): determines which jobs are brought into memory for processing.

The primary difference is in the frequency of their execution. The short term must select a new process
quite often. Long-term is used much less often since it handles placing jobs in the system and may wait a
while

5. What resources are used when a thread is created? How do they differ from those used when a
process is created?

Solution:

Because a thread is smaller than a process, thread creation typically uses fewer resources than process
creation. Creating a process requires allocating a process control block (PCB), a rather large data structure.
The PCB includes a memory map, list of open files, and environment variables. Allocating and managing
the memory map is typically the most time-consuming activity. Creating either a user or kernel thread
involves allocating a small data structure to hold a register set, stack, and priority.

6. What are the benefits of multithreaded system?

Solution:

• Increased responsiveness - Even if one thread is blocked, other threads can still run.
• Resource sharing: - Code sharing, and memory sharing.
• Economy - Creation of threads uses fewer resources as compared to processes.
• Taking advantage of multiprocessors - Threads can run parallel on different processors.

7. Which of the following components of program state are shared across threads in a multithreaded
process?
a) Register values
b) Heap memory
c) Global variables
d) Stack memory

Solution:

The threads of a multithreaded process share heap memory and global variables. Each thread has its
separate set of register values and a separate stack.

8. Describe the actions taken by a kernel to context-switch between kernel level threads.

Solution:

Context switching between kernel threads typically requires saving the value of the CPU registers from the
thread being switched out and restoring the CPU registers of the new thread being scheduled.

9. What are two differences between user-level threads and kernel-level threads? Under what
circumstances is one type better than the other?

Solution:

§ User-level threads are unknown by the kernel, whereas the kernel is aware of kernel threads.
§ On systems using either M:1 or M:N mapping, user threads are scheduled by the thread library and
the kernel schedules kernel threads.
§ Kernel threads need not be associated with a process whereas every user thread belongs to a process.
Kernel threads are generally more expensive to maintain than user threads as they must be
represented with a kernel data structure.


10. State three common ways of establishing a relationship between user threads and kernel threads.

Solution:

Many-to-one Model, One-to-One Model, and Many-to-Many model

References:
• Abraham Silberschatz, Peter Baer Galvin, Greg Gagne, “Operating System Concepts”, 9/E, John Wiley &
Sons, 2013.

Potrebbero piacerti anche