Presentation is loading. Please wait.

Presentation is loading. Please wait.

CGS 3763 Operating Systems Concepts Spring 2013

Similar presentations


Presentation on theme: "CGS 3763 Operating Systems Concepts Spring 2013"— Presentation transcript:

1 CGS 3763 Operating Systems Concepts Spring 2013
Dan C. Marinescu Office: HEC 304 Office hours: M-Wd 11: :30 AM

2 Lecture 10 – Wednesday, January 30, 2013
Last time: Answers to student questions Interrupt processing Kernel data structures for process management Today: Context switching Kernel functions for process management Creation and termination of processes Inter-process communication Shared memory Message passing Next time Reading assignments Chapters 3 and 4 of the textbook Chapters 3 and 4 textbook slides 11/13/2018

3 Context switching The storing and restoring the state (context) of a process so that execution can be resumed from the same point at a later time. Enables multiple processes/threads to share a single CPU.  11/13/2018

4 Process Control Block (PCB)

5 CPU Switch From Process to Process

6 Control data structure maintained by the kernel
To carry out its functions the kernel must maintain information about all objects in the system. For example: Processes  Process Control Block (PCB) Open files  File Control Block (FCB) 11/13/2018

7 Process Control Block (PCB)
The entry for a process contains the following information Process state Program counter CPU registers CPU scheduling information Memory-management information Accounting information I/O status information

8 Process Control Block (PCB)

9 The state of a process 11/13/2018

10 Interrupt handlers are a component of the kernel
11/13/2018

11 11/13/2018

12 11/13/2018

13 Kernel functions for program execution
Process management Scheduling and resource allocation Interrupt handling Error handling 11/13/2018

14 System calls for process control
Load Execute Create, terminate a process Block a process, abort Get process attributes/set process attributes Allocate/deallocate memory for a process 11/13/2018

15 Process Scheduling Queues
Job queue – set of all processes in the system Ready queue – set of all processes residing in main memory, ready and waiting to execute Device queues – set of processes waiting for an I/O device Processes migrate among the various queues

16 11/13/2018

17 Process Creation Parent process create children processes, which, in turn create other processes, forming a tree of processes Generally, process identified and managed via a process identifier (pid) Resource sharing Parent and children share all resources Children share subset of parent’s resources Parent and child share no resources Execution Parent and children execute concurrently Parent waits until children terminate

18 Process Creation (Cont’d)
Address space Child duplicate of parent Child has a program loaded into it 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

19 Process Creation

20 C Program Forking Separate Process
int main() { pid_t pid; /* fork another process */ pid = fork(); 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);

21 A tree of processes on a typical Solaris

22 Process Termination 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 children processes (abort) Child has exceeded allocated resources Task assigned to child is no longer required If parent is exiting Some operating system do not allow child to continue if its parent terminates All children terminated - cascading termination

23 Interprocess Communication
Processes within a system may be independent or cooperating Cooperating process can affect or be affected by other processes, including sharing data Reasons for cooperating processes: Information sharing Computation speedup Modularity Convenience Cooperating processes need interprocess communication (IPC) Two models of IPC Shared memory Message passing

24 Communications Models

25 Cooperating Processes
Independent process cannot affect or be affected by the execution of another process Cooperating process can affect or be affected by the execution of another process Advantages of process cooperation Information sharing Computation speed-up Modularity Convenience

26 Producer-Consumer Problem
Paradigm for cooperating processes, producer process produces information that is consumed by a consumer process unbounded-buffer places no practical limit on the size of the buffer bounded-buffer assumes that there is a fixed buffer size


Download ppt "CGS 3763 Operating Systems Concepts Spring 2013"

Similar presentations


Ads by Google