CSCE 313 Lecture 6

From Notes
Jump to navigation Jump to search

« previous | Thursday, February 2, 2012 | next »

Process Termination

exit
standard termination by process itself
output data to parent via wait
abort
parent forces child to terminate
used mainly when errors are encountered

When a parent process terminates leaving children processes still running, those processes are called zombies. Hence the need for cascading termination

Threads

Traditionally, processes do not interact with each other, but modern systems sometimes want to have multiple, tightly coupled processes.

Threads have access to the same data and resources (e.g. files), but each thread has its own stack and registers.

Switching Paradigms

Processes are too expensive to create and switch between since each has its own memory address space. Threads are extremely lightweight "processes" within a process that all share the same memory space.

In addition to the process control block, each thread has a thread control block.

Benefits:

  1. Increase responsiveness of an interactive application
  2. Sharing resources
  3. Faster creation and context-switching (In Solaris, creating a process is 30 times slower than creating a thread, and context-switching is 5 times slower)
  4. Scalability on multiprocessor architectures

User-Level vs. Kernel-Level

Determines who handles the thread processing

Java, pthreads, and Win32 threads are user-level thread libraries.

Mapping from user threads to kernel threads

Many-to-one
One thread at the kernel level can represent many user-level threads
Protection of kernel data is trivial, but is it really concurrent? (no)
One-to-one
For every user thread, there is a corresponding kernel-level thread
Special protection needed for shared data, but it is concurrency
Many-to-many
Mixed mapping: one kernel thread can represent multiple user threads, or many kernel threads can be handling a single user thread
Some operating systems use 2-level: same as M:M, but allows user threads to be bound to kernel threads

Threading Issues

Semantics of fork and exec

Will calling fork() duplicate the current thread or all thredas? (only the calling thread)

exec() replaces the entire process—including all threads.

Thread Cancellation

Asynchronously
terminate the target thread immediately
Deferred
Allows the thread to check if it should terminate

Signal Handling

A common signal handler for the process is used to relay signals to threads

Thread Pools

Create a number of threads in a pool where they await work.

Reduces overhead of creating threads, but requires more management.

Thread-Specific Data

Each thread can have its own copy of data

Thread Scheduling

Kernel has to communicate with thread handler to maintain mapping between threads. The communication method is called upcalls


CPU Scheduling

A more detailed discussion about how the CPU does what it does.

There are three basic schedulers:

  1. long-term: used in creation of process
  2. medium-term: used when writing a process to memory and loading from
  3. short-term: used when telling CPU which thread to execute next

The goal of the schedulers is to keep the CPU busy as much as possible (most efficient)

Decision Points:

  1. When a process goes from waiting to running
  2. When the process terminates
  3. When the process becomes ready from waiting for I/O
  4. When the process is switched from running to ready

Structure

  1. (Scheduler) Pick a process from the ready queue
  2. Dispatch the process to be executed

Criteria for selection

User-oriented:

  • Turnaround time: time from submission of job to its completion
  • Waiting time: Sum of periods spent waiting in ready queue
  • Response time: time interval from submission of job to its response
  • Normalized turnaround time: ratio of turnaround time to service time

System-oriented:

  • CPU Utilization: Percentage of time the CPU is busy
  • Throughput: number of jobs completed per time unit

Goal is to Maximize CPU Utilization and Throughput