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

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Process Control. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Creating and Executing Processes
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,
System calls for Process management
Operating Systems Processes 1.
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.
Operating Systems Process Creation
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Process Management Azzam Mourad COEN 346.
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.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
Section 8: Processes What is a process Creating processes Fork-Exec
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.
Protection of System Resources
Unix Process Management
Chapter 3: Process Concept
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
UNIX PROCESSES.
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.
Chapter 3: Processes.
Processes in Unix, Linux, and Windows
CGS 3763 Operating Systems Concepts Spring 2013
Fork and Exec Unix Model
Lecture 2: Processes Part 1
EECE.4810/EECE.5730 Operating Systems
CGS 3763 Operating Systems Concepts Spring 2013
Processes in Unix, Linux, and Windows
CGS 3763 Operating Systems Concepts Spring 2013
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
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
EECE.4810/EECE.5730 Operating Systems
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
EECE.4810/EECE.5730 Operating Systems
System Programming: Process Management
Presentation transcript:

EECE.4810/EECE.5730 Operating Systems Instructor: Dr. Michael Geiger Spring 2019 Lecture 4: Processes and process management (cont)

Announcements/reminders Program 1 to be posted; due 2/11 Will introduce in class Friday Will include details for logging in/remote access 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 ASAP Need to schedule in-class exams Original plan won’t work; poll to be posted 7/15/2019 Operating Systems: Lecture 4

Operating Systems: Lecture 4 Lecture outline Review Using return value of fork() wait() Operating on processes Using exec() calls to start new processes Process termination 7/15/2019 Operating Systems: Lecture 4

Review: Process creation 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 7/15/2019 Operating Systems: Lecture 4

Review: 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 7/15/2019 Operating Systems: Lecture 4

Review: fork()/wait() 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]); 7/15/2019 Operating Systems: Lecture 4

Review: fork()/wait() solution Since fork() copies all data from parent, 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 7/15/2019 Operating Systems: Lecture 4

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 7/15/2019 Operating Systems: Lecture 4

Command line arguments Provide arguments to executable at start Example: ./program1 2 3 Access arguments in main() if written as: int main(int argc, char **argv) { … } argc: argument count # of arguments—would be 3 in example above Executable name is first “argument” argv: argument vector List of strings containing arguments So, in example, argv[0] = "./program1", argv[1] = "2", argv[2] = "3" 7/15/2019 Operating Systems: Lecture 4

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; 7/15/2019 Operating Systems: Lecture 4

Operating Systems: Lecture 4 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 7/15/2019 Operating Systems: Lecture 4

Operating Systems: Lecture 4 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 7/15/2019 Operating Systems: Lecture 4

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 7/15/2019 Operating Systems: Lecture 4

Operating Systems: Lecture 4 Final notes Next time Inter-process communication Reminders: Program 1 to be posted; due 2/11 Will introduce in class Friday Will include details for logging in/remote access 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 ASAP Need to schedule in-class exams Original plan won’t work; poll to be posted 7/15/2019 Operating Systems: Lecture 4

Operating Systems: Lecture 4 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 7/15/2019 Operating Systems: Lecture 4