Operating Systems Review ENCE 360.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

 2004 Deitel & Associates, Inc. All rights reserved. 1 Chapter 3 – Process Concepts Outline 3.1 Introduction 3.1.1Definition of Process 3.2Process States:
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
Inter Process Communication:  It is an essential aspect of process management. By allowing processes to communicate with each other: 1.We can synchronize.
3.5 Interprocess Communication
CSSE Operating Systems
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
1/26/2007CSCI 315 Operating Systems Design1 Processes Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Concurrent Programming. Concurrency  Concurrency means for a program to have multiple paths of execution running at (almost) the same time. Examples:
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
CE Operating Systems Lecture 13 Linux/Unix interprocess communication.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
What is an Operating System? Various systems and their pros and cons –E.g. multi-tasking vs. Batch OS definitions –Resource allocator –Control program.
R Some of these slides are from Prof Frank Lin SJSU. r Minor modifications are made. 1.
ECE 297 Concurrent Servers Process, fork & threads ECE 297.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Lecture 3 Process.
Processes and threads.
Chapter 3: Processes.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
CS 6560: Operating Systems Design
Advanced OS Concepts (For OCR)
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Chapter 3 – Process Concepts
Process Management Presented By Aditya Gupta Assistant Professor
Processes Overview: Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 3: Processes Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 3: Processes.
Threads and Cooperation
Threads & multithreading
Applied Operating System Concepts
Chapter 3: Processes.
CGS 3763 Operating Systems Concepts Spring 2013
Lecture 2: Processes Part 1
System Structure B. Ramamurthy.
CGS 3763 Operating Systems Concepts Spring 2013
System Structure and Process Model
Operating Systems Lecture 6.
CGS 3763 Operating Systems Concepts Spring 2013
Process & its States Lecture 5.
Mid Term review CSC345.
Chapter 3: Processes.
Inter-Process Communication ENCE 360
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Chapter 3: Processes.
Concurrency: Processes CSE 333 Summer 2018
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Process Synchronization
Process Description and Control in Unix
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Process Description and Control in Unix
Chapter 3: Processes Process Concept Process Scheduling
Chapter 3: Process Concept
Lecture 6 Introduction to Process Management
Processes August 10, 2019 OS:Processes.
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Operating Systems Review ENCE 360

High-level Concepts What are three conceptual pieces fundamental to operating systems?

High-level Concepts What are three conceptual pieces fundamental to operating systems? Virtualization – sharing computer hardware in time and space Concurrency – simultaneous access to shared resources Persistence – making information exist across power outages, crashes, etc.

Operating System Model Arrange layers in order, top (user) to bottom Device driver (e.g., mouse) Computer game (e.g., FIFA 2018) Shell (e.g., Bash) Physical devices (e.g., Hard disk) Operating System (e.g., Linux) Program control (e.g., Task Manager)

Operating System Model Arrange layers in order, top (user) to bottom Music App Web Browser Game Applications Task Manager Shell Shell System Programs Operating System Device Driver A Device Driver B Device Driver C Hardware Physical Devices

The Process What is a process?

The Process What is a process? “A program in execution”

Process States What are the 3 main process states? What are the transitions between them?

Process States What are the 3 main process states? What are the transitions between them? Clean up Running Initialization Terminate Dispatch I/O request Create Interrupt Ready Waiting I/O complete

Process Control Block What is a process control block? What are the main components?

Process Control Block What is a process control block? A data structure the OS uses to manage a running program (a process) What are the main components? Running current code stuff – PC, registers, state, … Memory stuff – stack, heap, code, … I/O stuff – file descriptors, working directory, …

Process Creation in Unix main() { fork(); puts(“hello”); } What does the code to the left do when run? How can we change it to only have child process print “hello”?

Process Creation in Unix main() { fork(); puts(“hello”); } What does the code to the left do when run? hello How can we change it to only have child process print “hello”? Change fork() line to be: if (fork() == 0)

Processes and Threads What is a process? What is a thread? For two processes, what is private? For two threads in the same process, what is private?

Processes and Threads What is a process? What is a thread? A program in execution / a running program What is a thread? A single sequence of execution within a process For two processes, what is private? Code, memory (global variables, stack), hardware state (program counter, registers), OS resources (file descriptors+) For two threads in the same process, what is private? Memory (stack), Hardware state (program counter, registers)

Processes and Threads For two processes, what is private? For two threads in the same process, what is private? (Helpful picture)

Thread Creation with Pthreads void A() { puts(“hello”); } void main() { pthread_create(&t,A); puts(“goodbye”); What does the code to the left do when run?

Thread Creation with Pthreads void A() { puts(“hello”); } void main() { pthread_create(&t,A); puts(“goodbye”); What does the code to the left do when run? goodbye or hello hello goodbye What code to add to always have “hello” before “goodbye”?

Thread Creation with Pthreads void A() { puts(“hello”); } void main() { pthread_create(&t,A); pthread_join(t); puts(“goodbye”); What does the code to the left do when run? goodbye or hello or goodbye hello goodbye What code to add to always have “hello” before “goodbye”? pthread_join(t) before puts(“goodbye”)

IPC Paradigms What are two main paradigms for Interprocess Communication (IPC)? What are some advantages/disadvantages for each?

IPC Paradigms What are two main paradigms for Interprocess Communication (IPC)? What are some advantages/disadvantages for each? Message passing Good: explicit, less chance for programmer error Bad: overhead Shared memory Good: performance, flexibility for programmer Bad: changes without process knowing (side effects), programmer needs to handle sync

IPC Mechanisms What are some IPC mechanisms?

IPC Mechanisms What are some IPC mechanisms? Pipe Files Shared memory Signals Sockets …

Pipe What is a pipe? What operations does it support?

Pipe What is a pipe? What operations does it support? IPC mechanism provided by OS Gives bounded-buffer, FIFO/queue access Write to one end, Read from other Block on full write, Block on empty read b l a h . c \0 read fd write fd

System Exploration File-descriptors and exec() Signal-signal Thread-signal Challenge: once you use dup2() to change STDOUT, can you restore it? Hint, see: https://stackoverflow.com/questions/11042218/c-restore-stdout-to-terminal

Dup2 From the user’s perspective, what does this code do? fd = open(“dup.txt”, O_WRONLY) dup2(fd, STDOUT_FILENO) What does it do from the system’s perspective?

Dup2 From the user’s perspective, what does this code do? fd = open(“dup.txt”, O_WRONLY) dup2(fd, STDOUT_FILENO) Opens a file and changes standard output to go to the file instead of the screen What does it do from the system’s perspective? Closes STDOUT_FILENO, copies the file descriptor to the new file descriptor 1 2 3 ... 1 2 3 ... stdout stdout file file Before dup2() After dup2()

Signals What is an operating system signal? Broadly describe how to write code to use one Provide an example of how signals might be used

Signals What is an operating system signal? A message to a process corresponding to an event, sent by either another process or the OS Broadly describe how to write code to use one Provide an example of how signals might be used

Signals What is an operating system signal? A message to a process corresponding to an event, sent by either another process or the OS Broadly describe how to write code to use one Write handler function Make system call Send signals Provide an example of how signals might be used

Signals What is an operating system signal? A message to a process corresponding to an event, sent by either another process or the OS Broadly describe how to write code to use one Write handler function Make system call Send signals Provide an example of how signals might be used Gracefully shut down upon ctrl-c Indicate to parent child has finished work Wake up and do some action upon an alarm …

Sockets What two (maybe three) pieces of information does a client need to know to connect to a server?

Sockets What two (maybe three) pieces of information does a client need to know to connect to a server? IP Address – gets data to right computer Port – gets data to right process (Network protocol – TCP or UDP) message agreed port any port socket Internet address = 138.37.88.249 Internet address = 138.37.94.248 other ports client server

Sockets – Put in Order for Client & Server send() connect() bind() close() recv() accept() listen() socket()

Sockets – Put in Order for Client & Server connect() send() recv() close() Server socket() bind() listen() accept() recv() close() send() connect() bind() close() recv() accept() listen() socket()

Sockets - Describe What is the difference between send() and recv() vs. read() and write()

Sockets - Describe What is the difference between send() and recv() vs. read() and write() Answer: send() and recv() have flags that may be useful E.g., MSG_PEEK, MSG_DONTWAIT

Sockets - Describe What does “non-blocking” mean for a socket?

Sockets - Describe What does “non-blocking” mean for a socket? Answer: recv()/send(), do not sleep if no data. Note: can be done for accept() too on server

CPU Scheduling Briefly describe the shortest time to completion first (STCF) algorithm Is STCF pre-emptive?

CPU Scheduling Briefly describe the shortest time to completion first (STCF) algorithm From ready to run processes, select process with shortest time to finish it’s CPU burst Is SCTF pre-emptive? Yes – if a process arrives that has a shorter completion time than the one currently running, it is chosen instead

CPU Scheduling Describe some rules that will make the MLFQ adaptive

CPU Scheduling Describe some rules that will make the MLFQ adaptive New processes at highest priority If process uses all of timeslice, reduce priority If process voluntarily blocks before timeslice expires, increase priority

Sempahore Define using: enqueue proc s = s - 1 sleep dequeue proc if (s < 0) then s = s + 1 wake proc if (s <= 0) then int sem_wait(sem_t &s) { } int sem_post(sem_t &s) {

Sempahore Define using: enqueue proc s = s - 1 sleep dequeue proc if (s < 0) then s = s + 1 wake proc if (s <= 0) then int sem_wait(sem_t &s) { s = s - 1 if (s < 0) add process to queue and sleep } int sem_post(sem_t &s) { s = s + 1 if (s <= 0) remove process from queue and wake

Critical Region Processes pid 0 & pid 1 What is this doing, in general? Can both be in critical region? What is inefficient? Fix with semaphore shared int turn; while (1) { while (turn != pid) /* spin */ ; /* critical region code */ if (pid == 1) turn = 0; else turn = 1; /* other code */ }

Critical Region Processes pid 0 & pid 1 What is this doing, in general? Strict alternation Can both be in critical region? No What is inefficient? Spin wait Maybe not alternate Fix with semaphore wait(s) /* cr */ signal(s) shared int turn; while (1) { while (turn != pid) /* spin */ ; /* critical region code */ if (pid == 1) turn = 0; else turn = 1; /* other code */ }