CS401 Study Guide
This study guide will help you get ready for the final exam. It discusses the key topics in each unit, walks through the learning outcomes, and lists important vocabulary terms. It is not meant to replace the course materials!
Unit 2: Processes and Threads
2a. Discuss the importance and use of threads and processes in an operating system
- Define and compare uniprogramming with multiprogramming.
- Define a virtual machine.
Uniprogramming refers to computer operating systems that use one thread at a time. Multiprogramming uses more than one thread at a time and involves multicore processors.
Uniprogramming is a relatively easy OS design, such as Microsoft's MS/DOS and Apple's early Mac or Macintosh computer, which required batch processing (one thing at a time). Since this system gets rid of concurrency by defining it away, there are no concurrency issues.
In order to allow several activities to occur at the same time, such as play music, send an email, talk on the phone, Instagram, Facebook, and other social media, multiple threads of computing activity need to run concurrently. These applications have no awareness of the other computing activity that is in communion with them.
The only way to accomplish all of this activity is to make each operation function as if it is the only operation in existence. In other words, it operates as a virtual machine, which is a program on a computer that works like it is a separate computer inside the main computer. The OS manages these operations and everything else in the computing environment.
Review this material in Concurrency: Processes, Threads, and Address Spaces.
2b. Describe concurrency
- Define concurrency and parallelism.
- Describe four challenges of concurrency.
- Define a virtual machine.
Concurrency refers to when many operations may be running at the same time, or interleaved in any arbitrary way. You should always assume several operations are running at the same time to ensure you understand the process correctly. Parallelism refers to when operations are definitely running at the same time.
Four challenges of concurrency include:
- Single resources for many operations are designed for single resource use alone. These operations are not aware that other operations may want to use that resource.
- The OS has to coordinate ALL of the activity.
- The virtual machine functions as if it is the only one running that needs resources.
- Concurrency introduces synchronization problems via shared data.
As we discussed above, a virtual machine is a program on a computer that works like it is a separate computer inside the main computer.
Wikipedia notes that a virtual machine is:
- a simple way to run more than one operating system on the same computer.
- a very powerful server can be split into several smaller virtual machines to use its resources better.
- can help with security. If the virtual machine is affected by a virus, the host operating system is unaffected.
- can be completely emulated, such as Java. This lets a program run on different types of computer without having to be converted into a code specific for it. They can communicate even though the programming languages are not the same.
As with many things in life, computing requires managing many objectives with limited resources. If resources, such as cost and space, were unlimited we would always use parallelism. We adopt concurrency because resource constraints make parallelism unpractical. In other words, we must share resources among activities in a single computing environment.
Review this material in Concurrency: Processes, Threads, and Address Spaces and Concurrency.
2c. Explain the difference between a thread and a process
- Define thread and explain why we need to protect them.
- How do we protect threads?
- Define a process. How many parts does a process have?
- Define a process state. Name and define the process states.
- Define a heavyweight process.
- Define a lightweight process.
- Define a parent process.
A thread is an independent fetch/decode/execute loop. A thread is the definition of unique computing operation activity. A thread consumes a single address space.
We need to protect threads because they are susceptible to crashing when all of the computer programs are running. Depending on where the thread exists in the OS, a faulty thread has the potential to crash the entire OS. We can prevent threads from crashing by protecting memory, input and output (I/O), and access to the processor, such as by using a timing system.
A computer operates by what is called a "bus". Think of this as a continuous row of busses around a block, with no gaps. Information gets on and off. The whole thing is controlled by a clock within the bus. This is how the computer gets information, to and from everywhere. Everything has to fit on the bus and is controlled by the bus.
A process is a momentary creation in computing we facilitate when hardware and software work together. It may be helpful to think about a computer process in the same way as our brain when we have a single thought. A process is an abstraction in computing, because when the hardware and software stop operating or working together the abstraction disappears. Think of a process as a conception that does not persist in reality.
In other words, a process represents what is needed to run a program: it is a momentary creation in computing occasioned by the effective and productive interaction between hardware and software. We create a process to perform what we want to accomplish.
A process has two parts or goals: 1. To run computer software, and 2. To protect resources.
A process state refers to the stages a process goes through in order to execute.
Process states include:
- New – no resources have been allocated.
- Ready – resources are allocated.
- Running – executing.
- Waiting – need allocating of I/O.
- Terminated – the process has ended.
A heavyweight process is an older understanding and use of computing OS processes where each process contains one thread and one address state. Computer engineers used this concept before they created the concept of threads.
A lightweight process is a more recent understanding of computing OS processes that introduced the concept of threads. It came about when more advanced hardware design and manufacturing allowed more code to execute during the same time period. A lightweight process allows more than one thread, but still only consumes one address space. This is a good thing.
A process is similar to a program. Think of a program as software that is not being run. Think of a process as software that is being run. So, the colloquial expression, "run the program" is somewhat inaccurate. "Run the process" is more technically accurate.
A process invokes or creates many threads. A thread is a particular, singular activity the computer engineer created to perform the unique thing they wanted by running the process. Running the process can create or invoke many threads. For example, a parent thread can generate other threads.
While you should try not to give computers human qualities, it may be helpful to think of a thread as if it were a thought.
Review this material in:
- Concurrency: Processes, Threads, and Address Spaces.
- Principles of Operating Systems: Processes and Principles of Operating Systems: Threads
- Processes and Process Management
- The Process Concept and Threads and Concurrency
- A Brief Introduction to Threads
2d. Discuss context switching and how it is used in an operating system
- Define context switching and multiplexing.
- Why do we need to switch processes?
- Name something to be avoided during context switching.
- Define overhead.
- Do modern operating systems have more or less overhead? Explain why or why not.
Context switching occurs when the OS switches between processes. For example, we often need to switch processes because different virtual machines are running which require access to limited resources. For optimal computing environments, the OS is the traffic cop that tells which process to run and when not to run.
Every time a context switch occurs, the OS must run and no processes will be running. Since processes produce the useful output we need and want, you can think about the OS operations between switching processes as overhead, which is wasted computing and time that allows processes to switch back and forth.
Modern OSs have more overhead because they are doing more. For example, they are running more lines of code to make the OS robust and not crash.
When computing resources are limited, such as time, money, or another practicality, single resources, such as a CPU or chip, must be shared. Context switching is a BIG part of what the OS does. Context switching is the basic idea behind multiplexing or scheduling how to share limited resources in the computing environment.
Review this material in:
- Concurrency: Processes, Threads, and Address Spaces
- Context Switching
- Context Switches
- Processes and Threads
- Putting the P in Threads
Unit 2 Vocabulary
- Context switching
- Context switching overhead
- Crash (computing)
- Exception (computing)
- Process state
- Shared Memory
- Stack overflow
- Virtual machine