CPSC 457- Operating Systems (Lab)

Sina Keshvadi

Week 9 and 10 - Race Condition

In week 9 and 10, we will talk about Race Condition.
Race Condition Notes

Programming Exercises

  1. simple_mutex.cpp: An example of thread-level parallelism in selling tickets.
  2. dining_philosophers.cpp: This program implements the classic dining philosophers simulation. This version works the vast majority of the time, but there's a non-zero chance the simulation deadlocks.
  3. dining_philosopher_busy_waiting.cpp : This program implements the classic dining philosophers simulation. This version removes the deadlock concern present in dining_philosophers.cpp, but it allows busy waiting.
  4. dining_philosopher_cv.cpp: This program uses condition variables to implement the classic dining philosophers simulation. This is the first version that actually does the right thing.
  5. dining_philosophers.cpp: This program implements the classic dining philosophers simulation using the sempahore class.
  6. writer_reader.cpp: Implements the classic reader-writer thread example, where one thread writes to a shared buffer and a second thread reads from it. This version uses no thread coordination and is BUGGY!
  7. writer_reader_fixed.cpp : Implements the classic reader-writer thread example, where one thread writes to a shared buffer and a second thread reads from it. This version uses thread coordination to ensure that the reader only reads valid data and the writer doesn't overwrite unread data.


Week 8 - Multi-Threadings

In week 8, we will talk about Multi-Threadings.
Multi-Threadings Notes

Programming Exercises

  1. simple_thread.cpp: This program creat a simple thread
  2. thread_array.ccp: This program spawns threads to each greet you, and we wait for all threads to finish before terminating.


Week 6 and 7 - Signals

In week 6 and 7, we will talk about Signals.
Signals Notes

Programming Exercises

  1. sigint.cpp: This program installs a SIGINT handler to catch the SIGINT (Ctrl+c) instead of the default behavior of terminating the program. (Use Ctrl+z instead to stop the program, and then kill -9 [PID] to terminate it (you can use SIGKILL instead of 9)).

  2. sig_children.cpp: This program illustrates how a SIGCHLD handler can be used to reap background child processes (and have it work when all background processes take varying lengths of time to complete).

  3. sigwait.cpp: This program is the same as sigint.cpp but instead of using a signal handler to handle SIGINT it waits for SIGTSTP signals using sigwait and then prints out a message to the user instead of the default behavior of terminating the program. (Use Ctl-c instead to stop the program).

  4. sig_children_2.cpp: This program illustrates how we can wait for SIGCHLD signals using sigwait instead of a signal handler to clean up background child processes.


Week 5 - Interprocess Communication

In week 5, we will talk about how processes communicate using pipe.
Interprocess Communication Notes

Programming Exercises

  1. pipe.cpp: This program demonstrate a basic use of pipe.
  2. pipe_fork.cpp: This program shows how pipe works across child and parent processes.
  3. subprocess.cpp: Implements the subprocess routine, which is similar to popen and allows the parent process to spawn a child process, print to its standard output, and then suspend until the child process has finished.
  4. pipeline.cpp: This example presents the implementation of the pipeline routine, which is similar to subprocess and allows the parent process to spawn two child processes, the first of which has its stdandard output forwarded to the second child's standard input. The parent then waits for both children to finish.


Week 3 and 4 - Multi Processing

In week 3 and 4, we will talk about Multi Processing.
Multi Processing Notes

Programming Exercises

  1. fork.cpp: This program illustrates the basics of fork. It has the clear flaw that the parent can finish before its child, and the child process isn't reaped by the parent.

  2. fork_file_sharing.cpp: This program creates a child process where both the parent and child seemingly access or modify the same string at the same address. But the string is different for both the parent and child.

  3. fork_random.cpp: An example that shows how a process and its child copy a random variable.

  4. fork_output.cpp: Small example illustrating fork and the potential for many possible outcomes that result from the concurrency and the various ways all of the children, grandchildren, etc. can be scheduled.

  5. waitpid.cpp: In this program a parent waits for its child to terminate.

  6. waitpid_status.cpp: Here's is a program that's written in a style more conistent with how fork is normally used.

  7. fork_exit_order.cpp: This example spawns off 8 children, each of which returns a different exit status. The main program waits until all child processes exit.

  8. execvp.cpp: Demonstrates the build-in execvp() function.

  9. simple-shell.cpp: A program containing an implementation of a working shell that can execute entered text commands. It relies on our own implementation of system(), called mysystem(), that creates a process to execute a given shell command.

  10. system.cpp: Demonstrates the build-in system() function.


Week 2 - System Calls and Assignment 1 Review

In this week we cover System Calls and review assignment 1.
File System Notes

Programming Exercises

  1. create_file.cpp: This program shows an example of creating a new file with a given name. Similar to the touch unix command, it creates the file if it doesn't exist. But in this case, if it does exist, it throws an error.

  2. copy.cpp: This program is the starter code for an example that shows how we can make a copy of a specified file into another specified file, similar to the cp unix command.

  3. copy_extended.cpp: This program is an implementation of an extended copy command that shows how we can make a copy of a specified file into multiple other specified files, as well as printing the contents to the terminal.


Week 1 - File System

In this week we review the Linux File System
File System Notes