PROCESSES & THREADS ADINA-CLAUDIA STOICA.

Slides:



Advertisements
Similar presentations
Processes and Threads Chapter 3 and 4 Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community College,
Advertisements

Processes Management.
Part IV: Memory Management
Chapter 3 Process Description and Control
©Brooks/Cole, 2003 Chapter 7 Operating Systems Dr. Barnawi.
1 Chapter 4 Threads Threads: Resource ownership and execution.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Chapter 51 Threads Chapter 5. 2 Process Characteristics  Concept of Process has two facets.  A Process is: A Unit of resource ownership:  a virtual.
Process by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Threads. Readings r Silberschatz et al : Chapter 4.
Processes 2 Introduction to Operating Systems: Module 4.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Embedded Real-Time Systems
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.
Modularity Most useful abstractions an OS wants to offer can’t be directly realized by hardware Modularity is one technique the OS uses to provide better.
Introduction to Kernel
Processes and threads.
Chapter 2 Memory and process management
Process Management Process Concept Why only the global variables?
Chapter 3: Process Concept
CS 6560: Operating Systems Design
Operating System Concepts
Operating Systems (CS 340 D)
OPERATING SYSTEMS CS3502 Fall 2017
Computer Architecture
Multithreaded Programming in Java
CS399 New Beginnings Jonathan Walpole.
Process Management Presented By Aditya Gupta Assistant Professor
William Stallings Computer Organization and Architecture
Chapter 4 Threads.
Process Description and Control
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)
Threads & multithreading
Chapter 4: Threads.
Operating System Concepts
Operating Systems (CS 340 D)
Lecture 2: Processes Part 1
ICS 143 Principles of Operating Systems
Processor Fundamentals
Process & its States Lecture 5.
Operating Systems.
Memory Management Tasks
Chapter 3: Processes.
Chapter 8: Memory management
Outline Module 1 and 2 dealt with processes, scheduling and synchronization Next two modules will deal with memory and storage Processes require data to.
Process Description and Control
Lecture Topics: 11/1 General Operating System Concepts Processes
Threads Chapter 4.
Multithreaded Programming
Operating Systems (CS 340 D)
Prof. Leonardo Mostarda University of Camerino
Chapter 3: Processes.
Threads David Ferry CSCI 3500 – Operating Systems
Chapter 2 Processes and Threads 2.1 Processes 2.2 Threads
MULTITHREADING PROGRAMMING
Year 10 Computer Science Hardware - CPU and RAM.
Chapter 3: Processes Process Concept Process Scheduling
Concurrency: Threads, Address Spaces, and Processes
Chapter 3: Process Management
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

PROCESSES & THREADS ADINA-CLAUDIA STOICA

CONTENTS 1.Process 2.Thread 3.Processes VS. Threads 4.Why choose Process over Thread, or Thread over Process?

1.WHAT IS A PROCESS? A process is an instance of program execution. This means, for example, that if you open up two browser windows then you have two processes, even though they are running the same program.

Some essential resources every process needs are registers, a program counter, and a stack. The “registers” are data holding places that are part of the computer processor (CPU). A register may hold an instruction, a storage address, or other kind of data needed by the process.

The “program counter,” also called the “instruction pointer,” keeps track of where a computer is in its program sequence. The “stack” is a data structure that stores information about the active subroutines of a computer program and is used as scratch space for the process. It is distinguished from dynamically allocated memory for the process that is known as the “heap.”

A COMPUTER PROCESS

There can be multiple instances of a single program, and each instance of that running program is a process. Each process has a separate memory address space, which means that a process runs independently and is isolated from other processes. It cannot directly access shared data in other processes. Switching from one process to another requires some time (relatively) for saving and loading registers, memory maps, and other resources.

This independence of processes is valuable because the operating system tries its best to isolate processes so that a problem with one process doesn’t corrupt or cause havoc with another process. You’ve undoubtedly run into the situation in which one application on your computer freezes or has a problem and you’ve been able to quit that program without affecting others.

The life-cycle of a process can be described by a state diagram which has states representing the execution status of the process at various times and transitions that represent changes in execution status.

The life-cycle of a process

Ready state A process in the ready state has all of the resources that it needs for further execution except for a processor. It is normally held in a ready queue until a processor becomes available.

Running state A process in the running state has all of the resources that it needs for further execution, including a processor.

Blocked state A process that needs some resource other than a processor for further execution is in a blocked state. It is usually placed in a queue waiting for the needed resource.

Threads A thread is the unit of execution within a process. A process can have anywhere from just one thread to many threads.

Process vs thread

When a process starts, it is assigned memory and resources When a process starts, it is assigned memory and resources. Each thread in the process shares that memory and resources. In single-threaded processes, the process contains one thread. The process and the thread are one and the same, and there is only one thing happening.

In multithreaded processes, the process contains more than one thread, and the process is accomplishing a number of things at the same time

We talked about the two types of memory available to a process or a thread, the stack and the heap. It is important to distinguish between these two types of process memory because each thread will have its own stack, but all the threads in a process will share the heap.

Threads are sometimes called lightweight processes because they have their own stack but can access shared data. Because threads share the same address space as the process and other threads within the process, the operational cost of communication between the threads is low, which is an advantage. The disadvantage is that a problem with one thread in a process will certainly affect other threads and the viability of the process itself.

Threads vs processes 1.The program becomes one or more running processes. 2.Processes are typically independent of each other, 3.While threads exits as the subset of a process 4.Threads can communicate with each other more easily than processes can, 5.But threads are more vulnerable to problems caused by other threads in the same process

Process Processes are heavyweight operations Each process has its own memory space Inter-process communication is slow as processes have different memory addresses Context switching between processes is more expensive Processes don’t share memory with other processes

Thread Threads are lighter weight operations Threads use the memory of the process they belong to Inter-thread communication can be faster than inter- process communication because threads of the same process share memory with the process they belong to Context switching between threads of the same process is less expensive Threads share memory with other threads of the same process

Why Choose Process over Thread, or Thread over Process? So, how would a programmer choose between a process and a thread when creating a program in which she wants to execute multiple tasks at the same time? Let’s look at a real world example with a program that many of us use, Google Chrome.

When Google was designing the Chrome browser, they needed to decide how to handle the many different tasks that needed computer, communications, and network resources at the same time. Each browser window or tab communicates with multiple servers on the internet to retrieve text, programs, graphics, audio, video, and other resources, and renders that data for display and interaction with the user. In addition, the browser can open many windows, each with many tasks.

Google had to decide how to handle that separation of tasks Google had to decide how to handle that separation of tasks. They chose to run each browser window in Chrome as a separate process rather than a thread or many threads, as is common with other browsers. Doing that brought Google a number of benefits. Running each window as a process protects the overall application from bugs and glitches in the rendering engine and restricts access from each rendering engine process to others and to the rest of the system. Isolating a JavaScript program in a process prevents it from running away with too much CPU time and memory and making the entire browser non-responsive.

Google made a calculated trade-off with the multi- processing design Google made a calculated trade-off with the multi- processing design. Starting a new process for each browser window has a higher fixed cost in memory and resources than using threads. They were betting that their approach would end up with less memory bloat overall.

Using processes instead of threads also provides better memory usage when memory gets low. An inactive window is treated as a lower priority by the operating system and becomes eligible to be swapped to disk when memory is needed for other processes. That helps keep the user-visible windows more responsive. If the windows were threaded, it would be more difficult to separate the used and unused memory as cleanly, wasting both memory and performance.

Bibliography 1. https://www.backblaze.com/blog/whats-the-diff- programs-processes-and-threads/ 2. https://www.d.umn.edu/~gshute/os/processes- and-threads.xhtml 3. https://docs.microsoft.com/en- us/windows/desktop/procthread/processes-and- threads