Processes and threads.

Slides:



Advertisements
Similar presentations
Processes Management.
Advertisements

A. Frank - P. Weisberg Operating Systems Process Scheduling and Switching.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
CE Operating Systems Lecture 5 Processes. Overview of lecture In this lecture we will be looking at What is a process? Structure of a process Process.
Process Management. Processes Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication.
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,
Process by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Processes.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations on Processes Cooperating.
Processes – Part I Processes – Part I. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Review on OSs Upon brief introduction of OSs,
11/13/20151 Processes ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original.
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
1 Computer Systems II Introduction to Processes. 2 First Two Major Computer System Evolution Steps Led to the idea of multiprogramming (multiple concurrent.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Processes, Threads, and Process States. Programs and Processes  Program: an executable file (before/after compilation)  Process: an instance of a program.
Hardware process When the computer is powered up, it begins to execute fetch-execute cycle for the program that is stored in memory at the boot strap entry.
Chapter 2 Process Management. 2 Objectives After finish this chapter, you will understand: the concept of a process. the process life cycle. process states.
Operating Systems (CS 340 D) Dr. Abeer Mahmoud Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Processes. Process Concept Process Scheduling Operations on Processes Interprocess Communication Communication in Client-Server Systems.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
Chapter 3: Processes. 3.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 3: Processes Process Concept Process Scheduling Operations.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
1 Module 3: Processes Reading: Chapter Next Module: –Inter-process Communication –Process Scheduling –Reading: Chapter 4.5, 6.1 – 6.3.
Operating System Components) These components reflect the services made available by the O.S. Process Management Memory Management I/O Device Management.
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Lecture 3 Process.
Process concept.
Operating Systems CMPSC 473
Chapter 3: Processes.
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
Topic 3 (Textbook - Chapter 3) Processes
Operating System Concepts
Operating Systems (CS 340 D)
Sujata Ray Dey Maheshtala College Computer Science Department
OPERATING SYSTEMS CS3502 Fall 2017
Process Management Presented By Aditya Gupta Assistant Professor
Chapter 3: Processes.
Processes Overview: Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 3: Processes Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Chapter 3: Processes.
Intro to Processes CSSE 332 Operating Systems
Operating Systems (CS 340 D)
Chapter 3: Processes.
Process Virtualization. Process Process is a program that has initiated its execution. A program is a passive entity; whereas a process is an active entity.
Lecture 2: Processes Part 1
ICS 143 Principles of Operating Systems
Recap OS manages and arbitrates resources
Process & its States Lecture 5.
Chapter 3: Processes.
Operating System Concepts
Process Description and Control
Lecture Topics: 11/1 General Operating System Concepts Processes
Process Description and Control
Sujata Ray Dey Maheshtala College Computer Science Department
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
Chapter 3: Processes.
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
Outline Chapter 2 (cont) Chapter 3: Processes Virtual machines
Chapter 3: Processes Process Concept Process Scheduling
Chapter 3: Process Concept
Chapter 3: Process Management
Presentation transcript:

Processes and threads

Overview Process and Process states Operations on processes Process Scheduling Threads

Definition A process is a unit of work in a computer system. Processes, can be operating-system processes (those that execute system code) OR user / application processes (those that execute user code).

Processes The OS is responsible for the following activities related to process management: Scheduling processes and threads on the CPUs Creating and deleting both user and system processes Suspending and resuming processes Providing mechanisms for process synchronization Providing mechanisms for process communication

Process Vs Program A program by itself is not a process; a program is a passive entity, such as a file containing a list of instructions stored on disk (often called an executable file), whereas a process is an active entity, with a program counter specifying the next instruction to execute and a set of associated resources. A program becomes a process when an executable file is loaded into memory.

Process in memory

Process Memory Process memory is divided into four sections as shown on previous slide: The text section comprises the compiled program code, read in from non-volatile storage when the program is launched. The data section stores global and static variables, allocated and initialized prior to executing main. The heap is used for dynamic memory allocation during run time. The stack contains temporary data e.g. local variables. Space on the stack is reserved for local variables when they are declared and the space is freed up when the variables go out of scope. **** Note that the stack and the heap start at opposite ends of the process's free space and grow towards each other.

Process Memory Contd… When processes are swapped out of memory and later restored, additional information must also be stored and restored. Key among them are the program counter and the value of all program registers. A program counter is a register in a computer processor that contains the address (location) of the instruction being executed at the current time

Processes Although two processes may be associated with the same program, they are considered two separate execution sequences. For instance, several users may be running different copies of the mail program, or the same user may invoke many copies of the Web browser program. Each of these is a separate process; and although the text sections are equivalent, the data, heap, and stack sections vary. It is also common to have a process that spawns many processes as it runs.

Process States

Process States Contd… Processes may be in one of 5 states, as shown previously: New - The process is in the stage of being created. Ready - The process has all the resources available that it needs to run, but the CPU is not currently working on this process's instructions. Running - The CPU is working on this process's instructions. Waiting - The process cannot run at the moment, because it is waiting for some resource to become available or for some event to occur. For example the process may be waiting for keyboard input, disk access request, inter-process messages, a timer to go off, or a child process to finish. Terminated - The process has completed.

Process Control Block (PCB) For each process there is a PCB which stores the following process-specific information Process State - Running, waiting, etc., as discussed above. Process ID, and parent process ID. CPU registers and Program Counter - These need to be saved and restored when swapping processes in and out of the CPU. CPU-Scheduling information - Such as priority information and pointers to scheduling queues. Memory-Management information - E.g. page tables or segment tables. Accounting information - user and kernel CPU time consumed, account numbers, limits, etc. I/O Status information - Devices allocated, open file tables, etc.

Process Control Block (PCB)

Process Scheduling Its aim is to maximise CPU use by switching processes onto the CPU for time sharing The two main objectives of process scheduling are to keep the CPU busy at all times deliver "acceptable" response times for all programs, particularly for interactive ones. The process scheduler must meet these objectives by implementing suitable policies for swapping processes in and out of the CPU.

Scheduling Queues Job queue – set of all processes in the system Ready queue – set of all processes residing in main memory, waiting to execute Device queues –set of processes waiting for an I/O device to become available or to deliver data are placed in. There is generally a separate device queue for each device. ***Processes migrate among the various queues

Schedulers Long-term scheduler ( or Job Scheduler) – selects which processes should be brought into the ready queue . Invoked very infrequently Short-term scheduler ( or CPU Scheduler) – selects which process should be executed next and allocates CPU. Invoked very frequently.

Types of Processes Processes can be described as either: I/O-bound processes Spend more time doing I/O than computations, many short CPU bursts CPU-bound processes Spend more time doing computations; few very long CPU bursts

Medium-term Scheduler Some systems also employ a medium-term scheduler. When system loads get high, this scheduler will swap one or more processes out of the ready queue for a few seconds, in order to allow smaller faster jobs to finish up quickly and clear the system. An efficient scheduling system will select a good process mix of CPU-bound processes and I/O bound processes

Context Switch It is a process in which the CPU switches to another process In this case, the system must save the state of the old process and load the saved state for the new process (via a context switch) Context switch time is overhead; the system does no useful work while switching Time lost during context switching depends on the computer`s hardware support

Context Switch Whenever an interrupt arrives, the CPU must do a state-save of the currently running process, then switch into kernel mode to handle the interrupt, and then do a state-restore of the interrupted process. Similarly, a context switch occurs when the time slice for one process has expired and a new process is to be loaded from the ready queue. This will be instigated by a timer interrupt, which will then cause the current process's state to be saved and the new process's state to be restored. Saving and restoring states involves saving and restoring all of the registers and program counter(s), as well as the process control blocks described above.

Context Switching Contd… Context switching happens VERY VERY frequently, and the overhead of doing the switching is just lost CPU time, so context switches ( state saves & restores ) need to be as fast as possible. Some hardware has special provisions for speeding this up, such as a single machine instruction for saving or restoring all registers at once. Some hardware actually has multiple sets of registers, so the context switching can be speeded up by merely switching which set of registers are currently in use.

THREADS

Threads A program has one or more locus of execution. Each execution is called a thread of execution. The set of threads comprise a process. Each thread contains: **an instruction pointer (IP), a register with next instruction. **a stack for temporary data (eg, return addresses, parameters) **a data area for data declared globally and statically A process/thread is active, while a program is not.

Threads Modern systems allow a single process to have multiple threads of execution, which execute concurrently.

The Thread Model (1) (a) Three processes each with one thread (b) One process with three threads

The Thread Model (2) Items shared by all threads in a process Items private to each thread

Each thread has its own stack The Thread Model (3) Each thread has its own stack

A word processor with three threads Thread Usage A word processor with three threads

Tutorial What are the benefits of having threads? What is the relationship between threads multi-processor systems? Explain the differences between user-level threads and kernel-level threads.