CS 261 Fall Mike Lam, Professor. Processes

Similar documents
CS 261 Fall Mike Lam, Professor. Exceptional Control Flow and Processes

Announcement (1) sys.skku.edu is now available

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Q & A (1) Where were string literals stored? Virtual Address. SSE2033: System Software Experiment 2 Spring 2016 Jin-Soo Kim

Operating systems and concurrency - B03

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

CSC 1600 Unix Processes. Goals of This Lecture

Processes: Introduction. CS 241 February 13, 2012

TCSS 422: OPERATING SYSTEMS

OS Interaction and Processes

System Programming. Process Control II

UNIX Processes. by Armin R. Mikler. 1: Introduction

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

University of Washington What is a process?

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Carnegie Mellon. Processes. Lecture 12, May 19 th Alexandre David. Credits to Randy Bryant & Dave O Hallaron from Carnegie Mellon

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

Operating Systems Lab

Exceptional Control Flow Part I

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

Today. Introduction to Computer Systems /18 243, Fall th Lecture. Control Flow. Altering the Control Flow.

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

Processes. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! Scheduling processes

System Programming. Process Control III

System Programming. Signals II

Operating systems fundamentals - B06

CSC 252: Computer Organization Spring 2018: Lecture 19

Today. Exceptional Control Flow Processes. Exceptions and Processes. Control Flow. Altering the Control Flow

Exceptional Control Flow: Exceptions and Processes

Exceptional Control Flow Part I

Exceptional Control Flow Part I September 22, 2008

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

Altering the Control Flow

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

Process Creation and Control

Exceptional Control Flow Part I Oct. 17, 2002

Process Control. Philipp Koehn. 23 April 2018

Control Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow

Altering the Control Flow

SE350: Operating Systems

Giving credit where credit is due

CS 201. Processes. Gerson Robboy Portland State University

Processes. CSE 351 Autumn Instructor: Justin Hsia

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Processes. Dr. Yingwu Zhu

Processes. CSE 351 Autumn Instructor: Justin Hsia

Operating System Structure

Operating Systems. Lecture 05

Computer Science & Engineering Department I. I. T. Kharagpur

API Interlude: Process Creation (DRAFT)

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process?

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

518 Lecture Notes Week 3

Processes. Process Concept

Process! Process Creation / Termination! Process Transitions in" the Two-State Process Model! A Two-State Process Model!

EXPERIMENT NO : M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM,500GB HDD

PROCESS PROGRAMMING INTERFACE

Process Management! Goals of this Lecture!

Princeton University Computer Science 217: Introduction to Programming Systems. Process Management

INF1060: Introduction to Operating Systems and Data Communication. Pål Halvorsen. Wednesday, September 29, 2010

Program and OS interac0ons: Excep0ons and Processes

CS240: Programming in C

CS Operating Systems Lab 3: UNIX Processes

Princeton University Computer Science 217: Introduction to Programming Systems. Process Management

Processes, Exceptional

Processes. slide 1 kv, gm. Silberschatz chapter 3

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Process concepts. Processes. Process in Memory. Process Creation. definition of a process (sometimes called a Task) aprogram in execution

Princeton University. Computer Science 217: Introduction to Programming Systems. Process Management

Processes. q Process concept q Process model and implementation q Multiprocessing once again q Next Time: Scheduling

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Process Management 1

Concurrency. Stefan D. Bruda. Winter 2018

CSC209H Lecture 6. Dan Zingaro. February 11, 2015

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Process Management 1

Processes. CS3026 Operating Systems Lecture 05

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

Processes. Operating System CS 217. Supports virtual machines. Provides services: User Process. User Process. OS Kernel. Hardware

fork System-Level Function

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Exceptional Control Flow Part I Oct. 28, 2009"

Today: Process Management. The Big Picture So Far. What's in a Process? Example Process State in Memory

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

CSC 539: Operating Systems Structure and Design. Spring 2006

The Big Picture So Far. Today: Process Management

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

SOFTWARE ARCHITECTURE 3. SHELL

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Process Turnaround Time Total Wait Time P 1 12 ms 0 ms P 2 21 ms 12 ms P 3 23 ms 18 ms P 4 20 ms 17 ms

This document gives a general overview of the work done by an operating system and gives specific examples from UNIX.

Exceptions, Processes and Signals

CSE 153 Design of Operating Systems Fall 2018

Introduction to Processes

CITS2002 Systems Programming. Creating a new process using fork() 1 next CITS2002 CITS2002 schedule

Operating System. Chapter 3. Process. Lynn Choi School of Electrical Engineering

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

Transcription:

CS 261 Fall 2016 Mike Lam, Professor Processes

Processes Process: instance of an executing program Independent single logical flow and private virtual address space Logical flow: sequence of executed instructions Concurrency: overlapping logical flows Multitasking: processes take turns Parallelism: concurrent flows on separate CPUs/cores Time CPU Core1 Core2 Logical flow Concurrent flows Multitasking concurrent flows Parallel concurrent flows

Implementing processes Processes are abstractions Implemented/provided by the operating system kernel Kernel maintains data structure w/ process information Including an ID for each process (pid) Multitasking via exceptional control flow Periodic interrupt to switch processes Called round-robin switching Context switch: swapping current process Save context of old process Restore context of new process Pass control to the restored process

Linux process tools ps list processes "ps -fe" to see all processes on the system "ps -fu <username>" to see your processes top list processes, ordered by current CPU Auto-updates /proc virtual filesystem exposing kernel data structures pmap display memory map of a process strace prints a list of system calls from a process Compile with "-static" to get cleaner traces

Process creation The fork() syscall creates a new process Initializes new entry in the kernel data structures To user code, the function call returns twice Once for original process (parent) and once for new process (child) Returns 0 in child process Returns child pid in parent process Both processes will continue executing concurrently Parent and child have separate address spaces Child's space is a duplicate of parent's at the time of the fork They will diverge after the fork! Child inherits parent's environment and open files

Process creation example Fork returns twice! int main () { printf("before fork\n"); int pid = fork(); printf("after fork: pid=%d\n", pid); return 0;

Process creation example What does this code do? int main () { printf("before fork\n"); int pid1 = fork(); printf("after fork: pid1=%d\n", pid1); int pid2 = fork(); printf("after second fork: pid1=%d pid2=%d\n", pid1, pid2); return 0;

Process creation example Fork returns twice! (every time) Beware of non-determinism and I/O interleaving int main () { printf("before fork\n"); int pid1 = fork(); printf("after fork: pid1=%d\n", pid1); int pid2 = fork(); printf("after second fork: pid1=%d pid2=%d\n", pid1, pid2); return 0;

Process creation example Fork returns twice! (every time) Beware of non-determinism and I/O interleaving int main () { printf("before fork\n"); int pid1 = fork(); printf("after fork: pid1=%d\n", pid1); int pid2 = fork(); printf("after second fork: pid1=%d pid2=%d\n", pid1, pid2); return 0; Exercise: Modify this program to fork a total of three processes

Parent/child process example Parents can wait for children to finish int main () { printf("before fork\n"); int pid = fork(); if (pid!= 0) { // parent wait(null); printf("child has terminated.\n"); else { // child printf("child is running.\n"); printf("after fork: pid=%d\n", pid); return 0;

Process control syscalls #include <stdlib.h> getenv: get environment variable value setenv: change environment variable value #include <unistd.h> fork: create a new process getpid: return current process id (pid) exit: terminate current process execve: load and run another program in the current process sleep: suspend process for specified time period #include <sys/wait.h> waitpid: wait for a child process to terminate wait: wait for all child processes to terminate

Fork/execve example Shells use fork() and execve() to run commands int main () { printf("before fork\n"); int pid = fork(); if (pid!= 0) { // parent wait(null); printf("child has terminated.\n"); /bin/uname else { // child printf("child is running.\n"); char *cmd = "/bin/uname"; char *args[] = { "uname", "-a", NULL ; char *env[] = { NULL ; execve(cmd, args, env); printf("this won't print unless an error occurs.\n"); printf("after fork: pid=%d\n", pid); return 0;