Processes & Threads Today Next Time Process concept Process model

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

Operating Systems COMP 4850/CISG 5550 Processes Introduction to Threads Dr. James Money.
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Introduction to Processes
The Process Model.
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.
CSE 451: Operating Systems Winter 2006 Module 4 Processes Ed Lazowska Allen Center 570.
Processes CSCI 444/544 Operating Systems Fall 2008.
Page 1 Processes and Threads Chapter 2. Page 2 Processes The Process Model Multiprogramming of four programs Conceptual model of 4 independent, sequential.
Page 1 Processes and Threads Chapter Processes 2.2 Threads 2.3 Interprocess communication 2.4 Classical IPC problems 2.5 Scheduling.
CSCE 351: Operating System Kernels
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
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Process Description and Control A process is sometimes called a task, it is a program in execution.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes Tarek Abdelzaher Vikram Adve.
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.
Implementing Processes and Process Management Brian Bershad.
Multiprogramming CSE451 Andrew Whitaker. Overview Multiprogramming: Running multiple programs “at the same time”  Requires multiplexing (sharing) the.
The Structure of Processes. What is a Process? an instance of running program Program vs process(task) Program : just a passive collection of instructions.
Operating Systems Chapter 2
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,
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,
Operating Systems Processes 1.
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.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
1  process  process creation/termination  context  process control block (PCB)  context switch  5-state process model  process scheduling short/medium/long.
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.
Chapter 3: Processes.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Processes.
Processes A process is a running program.
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
System Structure B. Ramamurthy.
Processes in Unix, Linux, and Windows
System Structure and Process Model
Process & its States Lecture 5.
Chapter 3: Processes.
Process Description and Control
Processes Hank Levy 1.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Chapter 3: Processes.
October 7, 2002 Gary Kimura Lecture #4 October 7, 2002
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
EECE.4810/EECE.5730 Operating Systems
Processes Hank Levy 1.
EECE.4810/EECE.5730 Operating Systems
Presentation transcript:

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

EECS 343 Operating Systems Northwestern University The process model Most computers can do more than one thing at a time Hard to keep track of multiple tasks How do you call each of them? Process - program in execution a.k.a. job, task CPU switches back & forth among processes Pseudo-parallelism Multiprogramming on a single CPU At any instant of time one CPU means one executing task, but over time … Every processes as if having its own CPU Process rate of execution – not reproducible Four programs A B C D One PC A B C D Context switch EECS 343 Operating Systems Northwestern University

EECS 343 Operating Systems Northwestern University Process creation Principal events that cause process creation System initialization Execution of a process creation system User request to create a new process Initiation of a batch job In all cases – a process creates another one Running user process, system process or batch manager process Process hierarchy UNIX calls this a "process group" No hierarchies in Windows - all created equal (parent does get a handle to child, but this can be transferred) EECS 343 Operating Systems Northwestern University

EECS 343 Operating Systems Northwestern University Process creation Resource sharing Parent and children share all resources, a subset or none Execution Parent and children execute concurrently or parent waits Address space Child duplicate of parent or one of its own from the start UNIX example fork system call creates new process; a clone of parent Both processes continue execution at the instruction after the fork execve replaces process’ memory space with new one Why two steps? EECS 343 Operating Systems Northwestern University

EECS 343 Operating Systems Northwestern University Process identifiers Every process has a unique ID Since it’s unique sometimes used to guarantee uniqueness of other identifiers (tmpnam) Special process IDs: 0 – swapper, 1 – init Creating process in Unix – fork pid_t fork(void); Call once, returns twice Returns 0 in child, pid in parent, -1 on error Child is a copy of the parent Another option - COW (copy-on-write)? EECS 343 Operating Systems Northwestern University

Hierarchy of processes in Solaris sched is first process Its children pageout, fsflush, init … csh (pid = 7778), user logged using telnet … Sched pid = 0 fsflush pid = 3 init pid = 1 pageout pid = 2 inetd pid = 140 dtlogin pid = 251 telnetdaemon pid = 7776 xsession pid = 294 std_shel pid = 340 Csh pid = 7778 Firefox pid = 7785 xemacs pid = 8105 Csh pid = 140 ls pid = 2123 cat pid = 2536 EECS 343 Operating Systems Northwestern University

EECS 343 Operating Systems Northwestern University Process termination Conditions which terminate processes Normal exit (voluntary) the job is done Error exit (voluntary) oops, missing file? Fatal error (involuntary) Referencing non-existing memory perhaps? Killed by another process (involuntary) “kill -9” Unix – ways to terminate Normal – return from main, calling exit (or _exit) Abnormal – calling abort, terminated by a signal EECS 343 Operating Systems Northwestern University

I/O or event completion Process states Possible process states (in Unix run ps) New – being created Ready – waiting to get the processor Running – being executed Waiting – waiting for some event to occur Terminated – finished executing Transitions between states Which state is a process in most of the time? terminated exit new interrupt ready admitted running dispatched waiting I/O or event wait I/O or event completion EECS 343 Operating Systems Northwestern University

EECS 343 Operating Systems Northwestern University Process states in Unix User running Kernel running asleep Stopped + asleep Ready Initial (idle) Stopped zombie fork Syscall, interrupt Return from syscall or interrupt wait exit continue stop wakeup swtch sleep Process terminated but parent did not wait for it In 4.2/4.3 BSD, not in SVR2/SVR3 From U. Vahalia, UNIX Internal, Prentice-Hall, 1996 EECS 343 Operating Systems Northwestern University

Execution mode and context Mode of execution User mode Kernel mode Process context System context Kernel acts on behalf of the process Execution context Applications (user) code System calls, exceptions Not allowed Interrupts, system tasks (access process space only) (access process & system space) (access system space only) Kernel performs some system-wide task EECS 343 Operating Systems Northwestern University

Implementing processes A program in execution (i.e. more than code, text section) Program: passive; process: active Current activity Program counter & content of processor’s registers Stack – temporary data including function parameters, return address, … Data section – global variables Heap – dynamically allocated memory EECS 343 Operating Systems Northwestern University

Implementing processes OS maintains a process table of Process Control Blocks (PCB) PCB: information associated with each process Process state: ready, waiting, … Program counter: next instruction to execute CPU registers CPU scheduling information: e.g. priority Memory-management information Accounting information I/O status information … http://minnie.tuhs.org/UnixTree/V6/usr/sys/proc.h.html EECS 343 Operating Systems Northwestern University

Switch between processes Save current process’ state before Restore the state of a different one Context switch EECS 343 Operating Systems Northwestern University

Handling interrupts - again What gets done when an interrupt occurs HW stacks PC, etc HW loads new PC from interrupt vector Assembly lang. procedure saves registers Assembly lang. procedure sets up new stack C interrupt service runs Scheduler decides which process to run next C procedure returns to assembly code Assembly code starts up new current process EECS 343 Operating Systems Northwestern University

EECS 343 Operating Systems Northwestern University State queues OS maintains a collection of queues that represent the state of processes in the system Typically one queue for each state PCBs are queued onto state queues according to current state of the associated process As a process changes state, its PCB is unlinked from one queue, and linked onto another There may be many wait queues, one for each type of wait (devices, timer, message, …) EECS 343 Operating Systems Northwestern University

Process creation in UNIX #include <stdio.h> #include <sys/types.h> int tglob = 6; int main (int argc, char* argv[]) { int pid, var; var = 88; printf("write to stdout\n"); fflush(stdout); printf("before fork\n"); … … if ((pid = fork()) < 0){ perror("fork failed"); return 1; } else { if (pid == 0){ tglob++; var++; } else /* parent */ sleep(2); } printf("pid = %d, tglob = %d, var = %d\n", getpid(), tglob, var); return 0; } /* end main */ [fabianb@eleuthera tmp]$ ./creatone a write to stdout before fork pid = 31848, tglob = 7, var = 89 pid = 31847, tglob = 6, var = 88 EECS 343 Operating Systems Northwestern University

Process creation in UNIX #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main (void) { pid_t childpid; pid_t mypid; mypid = getpid(); childpid = fork(); if (childpid == -1) { perror("Failed to fork\n"); return 1; } if (childpid == 0) /* child code */ printf(“Child %ld, ID = %ld\n”, (long) getpid(), (long) mypid); else /* parent code */ printf(“Parent %ld, ID = %ld\n”, (long) getpid(), (long) mypid); return 0; [fabianb@eleuthera tmp]$ ./badpid 4 Child 3948, ID = 3947 Parent 3947, ID = 3947 EECS 343 Operating Systems Northwestern University

Process creation in UNIX ... if ((pid = fork()) < 0) { perror(“fork failed”); return 1; } else { if (pid == 0) { printf(“Child before exec … now the ls output\n”); execlp("/bin/ls", "ls", NULL); wait(NULL); /* block parent until child terminates */ printf("Child completed\n"); return 0; } } /* end main */ [fabianb@eleuthera tmp]$ ./creattwo Child before exec ... now the ls output copy_shell creatone.c~ p3id skeleton copy_shell.tar creattwo p3id.c uwhich.tar creatone creattwo.c p3id.c~ creatone.c creattwo.c~ Child completed EECS 343 Operating Systems Northwestern University

EECS 343 Operating Systems Northwestern University Summary Today The process abstraction Its implementation Processes in Unix Next time Threads EECS 343 Operating Systems Northwestern University