Process Tables; Threads

Slides:



Advertisements
Similar presentations
Process management Information maintained by OS for process management  process context  process control block OS virtualization of CPU for each process.
Advertisements

Concurrency. Motivation Operating systems (and application programs) often need to be able to handle multiple things happening at the same time – Process.
1 Created by Another Process Reason: modeling concurrent sub-tasks Fetch large amount data from network and process them Two sub-tasks: fetching  processing.
Processes CSCI 444/544 Operating Systems Fall 2008.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
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.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
Operating Systems (CSCI2413) Lecture 3 Processes phones off (please)
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.
System Calls 1.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Threads Many software packages are multi-threaded Web browser: one thread display images, another thread retrieves data from the network Word processor:
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
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.
Computer Studies (AL) Operating System Process Management - Process.
CS333 Intro to Operating Systems Jonathan Walpole.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
Operating Systems CSE 411 CPU Management Sept Lecture 10 Instructor: Bhuvan Urgaonkar.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
12/22/ Thread Model for Realizing Concurrency B. Ramamurthy.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
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.
Cs431-cotter1 Processes and Threads Tanenbaum 2.1, 2.2 Crowley Chapters 3, 5 Stallings Chapter 3, 4 Silberschaz & Galvin 3, 4.
What is a Process ? A program in execution.
2.2 Threads  Process: address space + code execution  There is no law that states that a process cannot have more than one “line” of execution.  Threads:
7/9/ Realizing Concurrency using Posix Threads (pthreads) B. Ramamurthy.
Threads prepared and instructed by Shmuel Wimer Eng. Faculty, Bar-Ilan University 1July 2016Processes.
Multiprogramming. Readings r Chapter 2.1 of the textbook.
Processes and threads.
Process Tables; Threads
Process concept.
CS 6560: Operating Systems Design
Protection of System Resources
CS399 New Beginnings Jonathan Walpole.
Introduction to Operating Systems
Intro to Processes CSSE 332 Operating Systems
Operating Systems Threads.
Processes in Unix, Linux, and Windows
Nachos Threads and Concurrency
Threads & multithreading
Introduction to Operating Systems
Processes in Unix, Linux, and Windows
More on UART Interrupts; System Calls
Operating Systems Lecture 13.
More examples How many processes does this piece of code create?
Processes in Unix, Linux, and Windows
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
PROCESS MANAGEMENT Information maintained by OS for process management
Threads Chapter 5 2/17/2019 B.Ramamurthy.
Jonathan Walpole Computer Science Portland State University
Threads Chapter 5 2/23/2019 B.Ramamurthy.
Still Chapter 2 (Based on Silberchatz’s text and Nachos Roadmap.)
Threads and Concurrency
Lecture 6: Multiprogramming and Context Switching
SE350: Operating Systems Lecture 3: Concurrency.
Processes David Ferry CSCI 3500 – Operating Systems
CSE 451: Operating Systems Winter 2003 Lecture 4 Processes
Unix Process Control B.Ramamurthy 4/11/2019 B.Ramamurthy.
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
CSE 451: Operating Systems Autumn 2004 Module 4 Processes
Threads CSE 2431: Introduction to Operating Systems
Presentation transcript:

Process Tables; Threads Reference on process tables text: Tanenbaum ch. 2.1 Reference on Threads text: Tanenbaum ch. 2.2

Memory Segments of a UNIX Process FFFFFFFF Variables Program 00000000

Implementation of Process Operating system maintains a process table one entry per process contains info such as program counter, stack pointer, memory allocation, status of open files, registers before state change, etc

Fields of a Process Table Entry

Process Management Field Registers (Saved registers) contains copies of CPU registers at the moment the process is blocked or being preempted the values are copied back into the CPU when the process is scheduled to run Stack pointer stores pointer to the process stack

Lowest Level of OS operations when an Interrupt Occurs

Interrupt Diagram Proc #3 Proc #4 iret User #1 Kernel Stack Data Code Proc #4 Stack Data iret Code User #1 Kernel Kernel Stack Proc #3 PC PSW etc #9 #3 ISR Process Table Save registers on stack; Set up new temporary stack ; Call C routine to service interrupts; Scheduler to decide which process to run next; Save registers, PSW, PC, stack for Proc #3; Load registers; Load PSW, PC, etc; Run Proc #4; Load registers,PSW,PC,stack for Proc #3; iret #4 Proc #3 Proc #4 Proc … TempStack

Interrupt Processing Steps Steps 1 and 2 A part of CPU Interrupt cycle CPU switches to kernel stack before pushing items on the stack Steps 3-8 interrupt handler Step 4 optional, many OS kernel allows interrupt handler to execute on the kernel stack Step 6 Scheduler loops through process table entries, looking for the highest priority ready process Step 8 Real process switch: CPU state and address space get switched Add a Step 9 iret will get delayed if a process switch occurs

Kernel Stack for Processes Each process needs its own kernel stack to execute in the kernel(e.g. making a syscall for read) If CPU gets blocked, whole execution environment held on stack and CPU state has to be saved before process switch Another process can also do a syscall and it needs a kernel stack as well. Implementation of process table and kernel stack varies from OS to OS

Kernel Stack and Interrupt Handlers Interrupt can occur during running of kernel code. Interrupt is doing work for another process that is blocked(e.g. ttyread and irqinthand in hw2). Borrow the current process’s kernel stack to execute interrupt handler. Kernel stack will be back to previous stack when handler finishes.

Threads Definition A thread has: execution flow of the process A thread has: PC: keep track of which instruction to execute next Registers: holds current working variables Stack: execution history State: running, blocked, ready or terminated Multithreading allows multiple execution to take place in the same process environment Achieves higher performance by avoiding address space switching between processes

The Thread Model (a) Three Processes (b) One Process 3 different address space and 3 threads(single thread) (b) One Process 1 address space and 3 threads (multithreading)

Operations of Multithreading Share the same address space (e.g. global variables), same resources( e.g. open files,, alarms and signals), same child processes etc. Owned by a single user Designed to work co-operatively. Use mutex in critical sections to make this happen.

A Multithreaded Web Server /*** dispatcher thread ***/ /*** worker thread ***/ while (TRUE){ while(TRUE){ get_next_request(&buf); wait_for_work(&buf); handoff_work(&buf); look_for_page_in_cache(&buf, &page); } if(page_not_in_cache(&page)) read_page_from_disk(&buf,&page); return_page(&page); }

Simplified POSIX Thread APIs void thread_create(thread, func, arg) Create a new thread Concurrent with the calling thread, thread executes func with argument arg void thread_yield() Calling thread voluntarily gives up the processor to let some other thread run The schedule can resume running the calling thread later int thread_join(thread) Wait for thread to finish; then return the value passed by thread_exit void thread_exit(ret) Finish the current thread Store the return value in the current thread’s data structure

A Simple Multi-Thread Program /* threadHello.c -- Simple multi-threaded program built with gcc -g -Wall -Werror -D_POSIX_THREAD_SEMANTICS threadHello.c -c -o threadHello.o gcc -g -Wall -Werror -D_POSIX_THREAD_SEMANTICS thread.c -c -o thread.o gcc threadHello.o thread.o -o threadHello –lpthread */ #include <stdio.h> #include "thread.h" static void go(int n); #define NTHREADS 10 static thread_t threads[NTHREADS]; int main(int argc, char **argv) { int i; long exitValue; for (i = 0; i < NTHREADS; i++){ thread_create(&(threads[i]), &go, i); } exitValue = thread_join(threads[i]); printf("Thread %d returned with %ld\n", i, exitValue); printf("Main thread done.\n"); return 0; } void go(int n) { printf("Hello from thread %d\n", n); thread_exit(100 + n); // Not reached }

Running threadHello.c $ ./threadHello Hello from thread 1 Thread 0 returned with 100 Thread 1 returned with 101 Thread 2 returned with 102 Thread 3 returned with 103 Thread 4 returned with 104 Thread 5 returned with 105 Thread 6 returned with 106 Thread 7 returned with 107 Thread 8 returned with 108 Thread 9 returned with 109 Main thread done.