CS 149: Operating Systems January 29 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
3.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Process An operating system executes a variety of programs: Batch system.
Advertisements

CS 149: Operating Systems February 3 Class Meeting
Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
Operating Systems High Level View Chapter 1,2. Who is the User? End Users Application Programmers System Programmers Administrators.
1 Last Time: OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
1 Processes and Pipes. 2 "He was below me. I saw his markings, manoeuvred myself behind him and shot him down. If I had known it was Saint-Exupery, I.
Chapter 1 Introduction
1 Introduction Chapter What is an operating system 1.2 History of operating systems 1.3 The operating system zoo 1.4 Computer hardware review 1.5.
1 CS 333 Introduction to Operating Systems Class 2 – OS-Related Hardware & Software The Process Concept Jonathan Walpole Computer Science Portland State.
1 What is a Process ? The activity of program execution. Also called a task or job Has associated with it: Code Data Resources A State An executing set.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
1 Introduction Chapter What is an operating system 1.2 History of operating systems 1.3 The operating system zoo 1.4 Computer hardware review 1.5.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Introduction Operating Systems’ Concepts and Structure Lecture 1 ~ Spring, 2008 ~ Spring, 2008TUCN. Operating Systems. Lecture 1.
CS 149: Operating Systems January 27 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Chapter 1 Introduction 1.1 What is an operating system
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S. TANENBAUM ALBERT S. WOODHULL Yan hao (Wilson) Wu University of the Western.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CSC 322 Operating Systems Concepts Lecture - 4: by Ahmed Mumtaz Mustehsan Special Thanks To: Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Introduction to Operating Systems Chapter 1. cs431 -cotter2 Lecture Objectives Understand the relationship between computing hardware, operating system,
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Chapter 1 Introduction 1.1 What is an operating system
1 Introduction Chapter What is an operating system 1.2 History of operating systems 1.3 The operating system zoo 1.4 Computer hardware review 1.5.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 1 Introduction Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
1 Chapter 2.1 : Processes Process concept Process concept Process scheduling Process scheduling Interprocess communication Interprocess communication Threads.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
CS 149: Operating Systems February 10 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Operating System Structure A key concept of operating systems is multiprogramming. –Goal of multiprogramming is to efficiently utilize all of the computing.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Chapter 1 Introduction  What is an operating system  History of operating systems  The operating system zoo  Computer hardware review  Operating system.
What is a Process ? A program in execution.
Concepts and Structures. Main difficulties with OS design synchronization ensure a program waiting for an I/O device receives the signal mutual exclusion.
2.1 Processes  process = abstraction of a running program  multiprogramming = CPU switches from running program to running program  pseudoparallelism.
CSCI/CMPE 4334 Operating Systems Review: Exam 1 1.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
10/2/20161 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam King,
Protection of System Resources
Chapter 2 Processes and Threads Today 2.1 Processes 2.2 Threads
Processes in Unix, Linux, and Windows
System Structure and Process Model
Processes in Unix, Linux, and Windows
System Structure B. Ramamurthy.
OPERATING SYSTEMS DESIGN AND IMPLEMENTATION Third Edition ANDREW S
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Processes in Unix, Linux, and Windows
2.1 Processes process = abstraction of a running program
Module 2.1 COP4600 – Operating Systems Richard Newman
Lecture Topics: 11/1 General Operating System Concepts Processes
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
Process Management -Compiled for CSIT
Process Management -Compiled for CSIT
Presentation transcript:

CS 149: Operating Systems January 29 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 2 Example System Call: fork() #include main() { printf("Parent: Process started.\n"); printf("Parent: Forking a child.\n"); if (fork() != 0) { int status; printf("Parent: Waiting for child to complete.\n"); waitpid(-1, &status, 0); printf("Parent: Child has completed.\n"); printf("Parent: Terminating.\n"); } else { printf("Child: Process started.\n"); printf("Child: Start 10 second idle:"); int i; for (i = 10; i >= 0; i--) { printf("%3d", i); fflush(stdout); sleep(1); } printf(" done!\n"); printf("Child: Terminating.\n"); } Executed by the parent. Executed by the child. The two processes fork at this point. forktest.c

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 3 The waitpid() System Call  What are the parameters?  Use the command-line UNIX man (for “manual”) command to get documentation of any system command or API call. _ waitpid(-1, &status, 0); Demo Pass the address of variable status (i.e., pass by reference).

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 4 Shell: I/O Redirection  For a program run on the command line: Standard input (stdin) is the keyboard. Standard output (stdout) is the terminal. #include #define MAX_LENGTH 256 main(int argc, char *args[]) { char *progname = args[0]; char line[MAX_LENGTH]; while (gets(line) != NULL) { printf("%s: %s\n", progname+2, line); } This program reads lines of text from stdin and echos them to stdout after prepending each line with the program name. echo.c Why the +2 ?

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 5 Shell: I/O Redirection  You can redirect a program’s stdin on the command line with the < operator: Now the echo program will read its own source file.  You can redirect a program’s stdout on the command line with the > operator: Now the echo program will write to file echo.txt. Use the >> operator to append to an output file.  You can redirect both stdout and stdin../echo < echo.c./echo echo.txt Demo

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 6 OS Concept: Pipes  Pipes are a mechanism for interprocess communication (IPC). One process writes to one end of a pipe. Another process reads from the other end. Each process believes it is doing file I/O. Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 7 Shell: Piping  You can pipe a program’s output to another program with the | operator: The first program’s stdout becomes the stdin for the second program.  What’s the result of this command?./echo1 |./echo2./echo1 < echo.txt |./echo2 |./echo3 Demo

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 8 The POSIX Standard  POSIX (Portable Operating System Interface)  IEEE standard for system calls.  Maintain compatibility among operating systems. UNIX and non-UNIX

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 9 Process Management System Calls  POSIX system calls.  Most modern operating systems have system calls that perform these functions. However, details may differ. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 10 File Management System Calls Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 11 File System Management System Calls Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 12 Miscellaneous System Calls Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 13 Kernel Mode vs. User Mode  An OS such as UNIX executes its critical system software in kernel mode. This is one way the OS protects itself.  As a user, you run utility programs (such as editors, compilers, and browsers) and application programs in user mode. System calls made by your programs can invoke some OS code that is executed in kernel mode.  On the command line, you can become “super user” and bypass some of the OS protection mechanisms.

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 14 Workflow of a System Call 1. Push nbytes 2. Push &buffer 3. Push fd 4. Invoke the read library routine. 5. Put the system call code for read in a register. 6. TRAP instruction switches to kernel mode to access the dispatcher in the OS kernel. 7. Dispatcher accesses the read handler. 8. Execute the read handler. 9. Return to the user program at the point after the TRAP instruction. Invoke the system call count = read(fd, buffer, nbytes) Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 15 Operating System Structure  There are various ways to organize the code of an operating system. Monolithic Layered Virtual machines Client-server Distributed _

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 16 OS Structure: Monolithic  The original classic way an OS was designed.  No structure. A collection of routines. Each routine can call any other routine. No information hiding.  A challenge to build and link.  An even bigger challenge to maintain and debug. Every software engineer should read the book The Mythical Man-Month about the development of IBM OS/360.

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 17 OS Structure: Layered  Organize the OS as a hierarchy of layers. Each layer built on top of the one below it. Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 18 OS Structure: Layered  Layers of the THE operating system. For a Dutch computer in the late 1960s. The bottommost layer 0 provided multiprogramming. _ Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 19 OS Structure: Virtual Machines  Virtual machines (VMs) were first developed for the IBM 370 in the late 1960s. Each virtual machine behaves like a separate physical machine. Controlled by a virtual machine monitor. Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 20 OS Structure: Virtual Machines  Modern VM monitors include: VirtualBox VMware KVM OpenVZ Xen

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 21 OS Structure: Client-Server  Put as much OS code as possible outside of the kernel and into user space.  OS services run as separate processes. Processes send messages to each other to request services. A “microkernel” serves as the communications bus. Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 22 OS Structure: Distributed  Like client-server, except that server processes run on different machines on the network. Service request messages go over the network. User programs do not need to know where the services are provided. _ Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 23 Processes  A process is basically an abstraction of a running program. The most central concept in any operating system.  Each process runs in its own address space. _

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 24 Process Models  Multiprogramming with multiple programs.  One program counter per CPU.  Each program has its own virtual CPU.  The real CPU rapidly switches from one program to another. Process switching AKA context switching Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 25 Process Models, cont’d  Only one program is active on a CPU at any instant. Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 26 Context Switching A process’s state information is kept in its process control block (PCB). Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 27 Process Creation  Principal events that cause processes to be created: System initialization. Execution of a process creation system call by a running process.  fork() A user request to create a new process. Initiation of a batch job.

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 28 Process Termination  Conditions that cause a process to terminate: Normal exit (voluntary). Error exit (voluntary). Fatal error (involuntary). Killed by another process (involuntary).  Cascading termination On some operating systems, when a process terminates, so do its child processes.

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 29 Process Creation and Termination What does the exec() system call do? Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc

Computer Science Dept. Spring 2015: January 29 CS 149: Operating Systems © R. Mak 30 Process States  Running  Actually using the CPU at that instant.  Ready  Runnable, but temporarily stopped to let another process run.  Blocked  Unable to run until some external event happens. Operating Systems: Design and Implementation, 3 rd ed. Andrew Tanenbaum & Albert Woodhull (c) 2006 Prentice-Hall, Inc