EECE.4810/EECE.5730 Operating Systems

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

CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Processes CSCI 444/544 Operating Systems Fall 2008.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
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
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-1 Process Concepts Department of Computer Science and Software.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-1: Process Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Computer Studies (AL) Operating System Process Management - Process.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
CS212: OPERATING SYSTEM Lecture 2: Process 1. Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Processes Dr. Yingwu Zhu. Process Concept Process – a program in execution – What is not a process? -- program on a disk - a process is an active object,
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 7, 2006 Chapter 3: Processes Process Concept.
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
System calls for Process management Process creation, termination, waiting.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Operating System Components) These components reflect the services made available by the O.S. Process Management Memory Management I/O Device Management.
Lecture 3 Process.
Chapter 3: Processes.
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Processes Chapter 3 These slides include text, figures, and information from Operating Systems Concepts, by Silberschatz, Galvin, and Gagne. They also.
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Process Concept
Chapter 3: Processes Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
Example questions… Can a shell kill itself? Can a shell within a shell kill the parent shell? What happens to background processes when you exit from.
System Structure and Process Model
Chapter 3: Processes.
System Structure and Process Model
Processes in Unix, Linux, and Windows
CGS 3763 Operating Systems Concepts Spring 2013
Lecture 2: Processes Part 1
System Structure B. Ramamurthy.
EECE.4810/EECE.5730 Operating Systems
CGS 3763 Operating Systems Concepts Spring 2013
Processes in Unix, Linux, and Windows
System Structure and Process Model
CGS 3763 Operating Systems Concepts Spring 2013
Process & its States Lecture 5.
Chapter 3: Processes.
Lab 5 Process Control Operating System Lab.
Process Creation Process Termination
Tutorial 3 Tutorial 3.
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Chapter 3: Process Concept
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
Presentation transcript:

EECE.4810/EECE.5730 Operating Systems Instructor: Dr. Michael Geiger Spring 2019 Lecture 2: Processes and process management

Operating Systems: Lecture 3 Lecture outline Announcements/reminders Program 1 to be posted this week; due TBD Office hours for Santosh: M/Th 11:30 AM-1:30 PM Hours will be in Linux lab (Ball 410) Will get card access for everyone this week Need to schedule in-class exams Original plan won’t work; poll to be posted Final exam time set: Saturday, 5/11, 8-11 AM Today’s lecture: more on processes Review process basics Operating on processes 5/8/2019 Operating Systems: Lecture 3

Operating Systems: Lecture 3 Review: Processes Process: program in execution 1+ running pieces of code (threads) + everything code can read/write Program counter Registers Address space Address space: all code/data stored in memory Text section: code Data section: global variables Stack: temporary data related to functions Heap: dynamically allocated data 5/8/2019 Operating Systems: Lecture 3

Operating Systems: Lecture 3 Review: Process State new: Process is being created running: Instructions are being executed waiting: Process waiting for some event to occur ready: Process waiting to be assigned to a processor terminated: Process has finished execution 5/8/2019 Operating Systems: Lecture 3

Review: Process Control Block (PCB) Stored in memory Used by OS to track process Some info updated with every change Process state Scheduling queue pointers Accounting info Memory management I/O status, File list Some info updated on context switch Running  waiting/ready state Save copies of PC, regs to PCB Restored when running again 5/8/2019 Operating Systems: Lecture 3

Review: Process creation Each process has to be created by another process Creator is called parent process Created process is child process Children can create other processes, forming process tree Graphical representation of parent/child relationships Parent/child processes may share resources Parent/child processes may execute concurrently, or parent may wait for child to terminate 5/8/2019 Operating Systems: Lecture 3

Review: Process creation (cont.) Address space Child duplicate of parent Same code/data (initially), different location Could run same program; could load new program UNIX examples fork() system call creates new process exec() system call used after a fork() to replace the process’ memory space with a new program wait() system call ensures child complete before parent continues/exits 5/8/2019 Operating Systems: Lecture 3

Example 1: process creation fork() system call creates new process as a duplicate of original process Copies original address space, code and all Including initial parent process, how many processes does the program below create? Draw a process tree to support your answer int main() { for (int i = 0; i < 4; i++) fork();   return 0; } 5/8/2019 Operating Systems: Lecture 3

Operating Systems: Lecture 3 Example 1 solution Each fork() call creates copy of currently running process Each copy runs same code! # processes doubles each loop iteration 1  2  4  8  16 5/8/2019 Operating Systems: Lecture 3

More details on fork() and wait() fork() return value is: <0 if fork() fails (no child created) 0 within child process PID of child (>0) within parent process Can use to differentiate child from parent Run same program but use conditional statement to send parent/child down different paths wait() system call allows parent to wait for child to finish execution 5/8/2019 Operating Systems: Lecture 3

Example 2: what does program print? int nums[5] = {0,1,2,3,4}; int main() { int i; pid_t pid; pid = fork(); if (pid == 0) { for (i = 0; i < 5; i++) { nums[i] *= -i; printf("CHILD: %d\n", nums[i]); } else if (pid > 0) { wait(NULL); for (i = 0; i < 5; i++) printf("PARENT: %d\n", nums[i]); 5/8/2019 Operating Systems: Lecture 3

Operating Systems: Lecture 3 Example 2 solution Since fork() copies all data from parent process, parent and child each get own copy Doesn’t matter if data are local or global nums[] array only changed in child Parent doesn’t print its array until child done So, output is: CHILD: 0 CHILD: -1 CHILD: -4 CHILD: -9 CHILD: -16 PARENT: 0 PARENT: 1 PARENT: 2 PARENT: 3 PARENT: 4 5/8/2019 Operating Systems: Lecture 3

Starting new program: exec system calls To start new program, replace address space of current process with new process On UNIX systems, use exec system calls Family of functions allowing you to specify Location of executable execlp(), execvp() don’t require full path Command line arguments to executable, either as Separate strings passed to execl(), execle(), execlp() Array of strings passed to execv(), execve(), execvp() Optional list of new environment variables 5/8/2019 Operating Systems: Lecture 3

Forking Separate Process int main() { pid_t pid; pid = fork(); // Create a child process if (pid < 0) { // Error occurred fprintf(stderr, "Fork failed"); return 1; } else if (pid == 0) { // Child process printf("Child: listing of current directory\n\n"); execlp("/bin/ls", "ls", NULL); else { // Parent process—wait for child to complete printf("Parent: waits for child to complete\n\n"); wait(NULL); printf("Child complete\n\n"); return 0; 5/8/2019 Operating Systems: Lecture 3

Operating Systems: Lecture 3 Process Termination Process ends using exit() system call May be explicit, implicit (return from main  exit()) Returns status data from child to parent (via wait()) Process’ resources are deallocated by operating system Parent may abort() executing child process if: Child has exceeded allocated resources Task assigned to child is no longer required Parent exiting and OS may not allow child to continue if parent terminates Not true in Linux, for example OS initiates cascading termination 5/8/2019 Operating Systems: Lecture 3

Operating Systems: Lecture 3 Process Termination Parent may wait() for child termination wait() returns child PID, passes return status through pointer argument pid = wait(&status); If child terminates before parent invokes wait(), process is a zombie If parent terminated without wait() , process is an orphan Return status must be checked In Linux, orphans assigned init as parent 5/8/2019 Operating Systems: Lecture 3

Process termination questions What’s downside of zombie processes? Unnecessary clutter and use of resources Worst case: fill process table Any reason to allow orphan processes? Long running process not requiring user Indefinitely running background process (daemon) Examples: respond to network requests (i.e. sshd), system logging (syslogd) Can 1 process be both zombie & orphan? Sure—child terminates first, then parent terminates without wait On UNIX system init “adopts” orphans to ensure exit status collected 5/8/2019 Operating Systems: Lecture 3

Operating Systems: Lecture 3 Final notes Next time Inter-process communication Reminders: Program 1 to be posted this week; due TBD Office hours for Santosh: M/Th 11:30 AM-1:30 PM Hours will be in Linux lab (Ball 410) Will get card access for everyone this week Need to schedule in-class exams Original plan won’t work; poll to be posted Final exam time set: Saturday, 5/11, 8-11 AM 5/8/2019 Operating Systems: Lecture 3

Operating Systems: Lecture 3 Acknowledgements These slides are adapted from the following sources: Silberschatz, Galvin, & Gagne, Operating Systems Concepts, 9th edition Chen & Madhyastha, EECS 482 lecture notes, University of Michigan, Fall 2016 5/8/2019 Operating Systems: Lecture 3