Operating Systems & Concurrency: Process Concepts

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

Chapter 3: Processes. Operating System Concepts 8th Edition,

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - III Processes. Louisiana State University. Virtual Machines Processes

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313: Intro to Computer Systems

Announcements Processes: Part II. Operating Systems. Autumn CS4023

Processes. Process Concept

CHAPTER 2: PROCESS MANAGEMENT

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Operating Systems CMPSC 473. Process Management January 29, Lecture 4 Instructor: Trent Jaeger

CS510 Operating System Foundations. Jonathan Walpole

Processes and Threads

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

Operating Systems. Lecture 05

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

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

Chapter 3: Process Concept

Chapter 3: Process Concept

Operating System Structure

Chapter 3: Process Concept

Part Two - Process Management. Chapter 3: Processes

Notice: This set of slides is based on the notes by Professor Perrone of Bucknell and the textbook authors Silberschatz, Galvin, and Gagne

Threads. Threads (continued)

Lecture 2 Process Management

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Chapter 3: Processes. Operating System Concepts Essentials 8 th Edition

Chapter 3: Processes

Chapter 3 Process Description and Control

COP 4610: Introduction to Operating Systems (Spring 2014) Chapter 3: Process. Zhi Wang Florida State University

518 Lecture Notes Week 3

Fall 2015 COMP Operating Systems. Lab #3

Chap 4, 5: Process. Dongkun Shin, SKKU

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

4.8 Summary. Practice Exercises

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

COP 4610: Introduction to Operating Systems (Spring 2016) Chapter 3: Process. Zhi Wang Florida State University

Chapter 3: Processes. Operating System Concepts 8th Edition

CS 3305 Intro to Threads. Lecture 6

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

Chapter 3: Processes. Operating System Concepts 8th Edition, modified by Stewart Weiss

Processes. Electrical and Computer Engineering Stephen Kim ECE/IUPUI RTOS & Apps 1

Chapter 3: Process Concept

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Creating Threads COMP755

Processes and Threads

Chapter 3: Processes. Operating System Concepts 8 th Edition,

Process. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

Chapter 3: Processes. Operating System Concepts 8 th Edition,

csci3411: Operating Systems

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Processes. CS3026 Operating Systems Lecture 05

Chapter 4: Processes. Process Concept

Chapter 4: Processes

CSC 539: Operating Systems Structure and Design. Spring 2006

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

Chapter 3: Processes

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

CS307 Operating Systems Processes

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

Multithreaded Programming

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

Process. Program Vs. process. During execution, the process may be in one of the following states

CS 326: Operating Systems. Process Execution. Lecture 5

CSC 1600 Unix Processes. Goals of This Lecture

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Operating systems fundamentals - B06

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

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

The Big Picture So Far. Today: Process Management

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

CHAPTER 3 - PROCESS CONCEPT

POSIX threads CS 241. February 17, Copyright University of Illinois CS 241 Staff

Concurrency. Stefan D. Bruda. Winter 2018

Killing Zombies, Working, Sleeping, and Spawning Children

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

Processes. Dr. Yingwu Zhu

Processes. Sanzheng Qiao. December, Department of Computing and Software

LSN 13 Linux Concurrency Mechanisms

Part V. Process Management. Sadeghi, Cubaleska RUB Course Operating System Security Memory Management and Protection

CPU/Process Management : Objectives & Challenges. Data Structures for CPU Management

Process Concepts 8/21/2014. CS341: Operating System. Scheduling: Theoretical Analysis

CMPSC 311- Introduction to Systems Programming Module: Concurrency

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

Computer Systems Assignment 2: Fork and Threads Package

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

CMPSC 311- Introduction to Systems Programming Module: Concurrency

CSci 4061 Introduction to Operating Systems. (Threads-POSIX)

The Big Picture So Far. Chapter 4: Processes

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

Chapter 3: Processes

Processes & Threads. Recap of the Last Class. Layered Structure. Virtual Machines. CS 256/456 Dept. of Computer Science, University of Rochester

CSE 153 Design of Operating Systems Fall 2018

Processes & Threads. Recap of the Last Class. Microkernel System Architecture. Layered Structure

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

Transcription:

Operating Systems & Concurrency: Process Concepts Michael Brockway October 6, 2011

Outline Processes - context, data area, states Process creation, termination unix examples Processes and threads

Processes Definition: A process is an instance of a program (an application) that is running under the managment of the operating system. A process runs sequentially Modern operating systems multitask they manage the simultaneous running of several (lots!) of application processes. The management is performed by a scheduler.

Processes Each process has a process ID a priority its own context and state (see below) CPU scheduling information file handles, network ports; I/O status information a data area; memory management information etc These data form a the fields of the process control block (PCB), aka task control block (TCB) for the process/task. The operating system keeps a table of PCBs for all of the currently executing processes.

Process context This is the set of values in all the CPU registers including the program counter: the address in memory from where the next instruction will be fetched the program status register: bits are set according to the result of the last operation; the current operation may test these bits the stack pointer: the address of the current top of the stack one or more data registers (accumulators) for holding data temporarily during a computation Subroutine calls are normally managed by storing return address, parameters, return value(s) on the stack

Process data area max memory allocated to process 0 Stack heap data text Figure: Data area for a process

Process states waiting born ready context switch running done Figure: Life cycle of states for a process In a multitasking system, there will be several (lots) of tasks (processes) running. One will be actually running on the CPU; the others will be ready. The scheduler periodically performs a context switch to give all the tasks a turn. Ususally this is rapid, giving the appearance of simultaneously, concurrently running processes. The processes/tasks are logically concurrent. If there are multple CPUs, there will be mutlple running tasks 1 per CPU. In this case we have some actual physical concurrency.

Process creation A parent process create children processes, which, in turn create other processes, forming a tree of processes. Generally, a process is identified and managed via a process identifier (pid) Resource sharing Parent and children share all resources; or Children share a subset of the parents resources; or Parent and child share no resources Execution Parent and children execute concurrently; or Parent waits until children terminate

Process creation - UNIX example The fork system call creates a new process The exec system call used after a fork to replace the process memory space with a new program parent wait resumes fork() child exec() exit() Figure: Fork exmaple

Process creation - UNIX example int main() { pid_t pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ fprintf(stderr, "Fork Failed"); exit(-1); else if (pid == 0) { /* child process */ execlp("/bin/ls", "ls", NULL); else { /* parent process */ /* parent will wait for the child to complete */ wait (NULL); printf ("Child Complete"); exit(0);

Processes termination (UNIX) Process executes last statement and asks the operating system to delete it (exit) Output data from child to parent (via wait) Process resources are deallocated by operating system Parent may terminate execution of child processes (abort) if child has exceeded allocated resources, or task assigned to child is no longer required, or if parent is exiting Some operating systems do not allow child to continue if its parent terminates: all children are terminated - cascading termination.

More on fork Notice from the code that fork returns an integer value - 0 if it is in the parent process a nonzero value in the child (clone) in fact, the process ID of the parent. If exec() is not used, fork simply creates a clone of the parent process: global variables, file handles etc are duplicated. Can you explain the behaviour of the following program (processdemo.c in Source files set 1, downloadable from here)? #include <stdio.h> int x = 50; /* a global variable */

More on fork void adjustx(char * legend, int i) { long p; while (1) /* loop forever */ { printf("%s: %i\n", legend, x); x += i; p=0; while (p<100000000) p++; /* a "busy" delay */ main() { int c; printf("creating new process:\n"); c = fork(); printf("process %i created\n", c); if (c==0) adjustx("child", 1); /* child process */ else adjustx("parent", -1); /* parent process */

Processes and Threads A simple process executes sequentially one operation at a time: a single-threaded process A process may be multithreaded Several threads, each one executes sequentially Each thread is scheduled as it if it were a separate process Each thread has its own subroutine stack Each thread has a distinct state, its own scheduling information But the threads belonging to a particular process share all other data, memory management information, file handles, network ports, I/O status information A thread is a light-weight process-like entity; part of a process. Normally a process is ended when all its threads have ended. A daemon is a thread which carries on executing after its parent process has finished.

UNIX (POSIX) Threads example: threaddemo.c The source file is in Source files set 1, downloadable from here. #include <stdio.h> #include <pthread.h> int x = 50; /* a global (shared) variable */ void * adjustx(void *n) { int i = (int)n; long p; while (1) /* loop forever */ { printf("adjustment = %i; x = %i\n", i, x); x += i; p=0; while (p<100000000) p++; /* a "busy" delay */ return(n);

UNIX (POSIX) Threads example main() { int a; pthread_t up_thread, dn_thread; pthread_attr_t *attr; /* thread attribute variable */ attr=0; printf("creating threads:\n"); pthread_create(&up_thread,attr, adjustx, (void *)1); pthread_create(&dn_thread,attr, adjustx, (void *)-1); while (1) /* loop forever */ { ;