Process A process is usually defined as an instance of a running program and consists of two components: A kernel object that the operating system uses.

Slides:



Advertisements
Similar presentations
Processes Management.
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Lesson 12: Kernel-mode Thread Sync (aka: Why I love Gentoo)
Chapter 2 Operating System Overview Operating Systems: Internals and Design Principles, 6/E William Stallings.
OS Fall ’ 02 Introduction Operating Systems Fall 2002.
ISP – 3 rd Recitation “The joy of Windows API” Processes Threads Handles Relevant functions A simple code example.
OS Spring’03 Introduction Operating Systems Spring 2003.
ISP – 4 th Recitation Times System Errors Threads Waits Code examples.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
Process Processes are executing or executable instances of programs. Processes in a modern OS haveOS –management information –resources –unique process.
Threads CNS What is a thread?  an independent unit of execution within a process  a "lightweight process"  an independent unit of execution within.
Process Description and Control A process is sometimes called a task, it is a program in execution.
OS Spring’04 Introduction Operating Systems Spring 2004.
Chapter 8 Windows Outline Programming Windows 2000 System structure Processes and threads in Windows 2000 Memory management The Windows 2000 file.
Win32 Programming Lesson 9: Jobs & Thread Basics.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 11 Case Study 2: Windows Vista Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Protection and the Kernel: Mode, Space, and Context.
1 Operating System Overview Chapter 2 Advanced Operating System.
Win32 Programming Lesson 13: Thread Pooling (Wow, Java is good for something…)
Threads, Thread management & Resource Management.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Win32 Programming Lesson 22: DLL Magic Part Deux All your base are belong to us…
The Structure of Processes (Chap 6 in the book “The Design of the UNIX Operating System”)
1 Confidential Enterprise Solutions Group Process and Threads.
Win32 Programming Lesson 18: More Memory Mapped Files and the HEAP (Finally, cool stuff!)
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 4 Memory Management Virtual Memory.
Operating Systems Lecture November 2015© Copyright Virtual University of Pakistan 2 Agenda for Today Review of previous lecture Hardware (I/O, memory,
Chapter 2 Processes and Threads Introduction 2.2 Processes A Process is the execution of a Program More specifically… – A process is a program.
Chapter 4: Multithreaded Programming. 4.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts What is Thread “Thread is a part of a program.
System Components ● There are three main protected modules of the System  The Hardware Abstraction Layer ● A virtual machine to configure all devices.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Threads, Thread management & Resource Management.
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.
Windows Threading Colin Roby Jaewook Kim.
What is a Process ? A program in execution.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 4: Processes Process Concept Process Scheduling Types of shedulars Process.
Win32 Synchronization CS Spring Overview Kernel Synchronization - Spinlocks Executive Synchronization - Dispatcher Objects Wait Operations.
Embedded Real-Time Systems Processing interrupts Lecturer Department University.
System Components Operating System Services System Calls.
Advanced Operating Systems CS6025 Spring 2016 Processes and Threads (Chapter 2)
Embedded Real-Time Systems
Window Threads Chapter 7 Windows Thread Management.
Principles of Operating Systems Abhishek Dubey Daniel Balasubramanian Fall 2014 Slides Based On Power points and book material from William Stallings.
Introduction to Operating Systems Concepts
Chapter 3: Windows7 Part 5.
Processes and threads.
PROCESS MANAGEMENT IN MACH
OPERATING SYSTEMS CS3502 Fall 2017
Threads and Locks.
Chapter 3: Windows7 Part 5.
Mid Term review CSC345.
Chapter 05. Multithread.
Lecture Topics: 11/1 General Operating System Concepts Processes
Process Description and Control
Threads Chapter 4.
Process Description and Control
Operating Systems Lecture 3.
Process Description and Control
Process Description and Control
Process Description and Control
Process Description and Control
February 5, 2004 Adrienne Noble
Operating Systems: A Modern Perspective, Chapter 3
Computer System Structures
CS510 Operating System Foundations
CS 143A Principles of Operating Systems
Process Description and Control
Chapter 2 Operating System Overview
Memory allocation.
Presentation transcript:

Process A process is usually defined as an instance of a running program and consists of two components: A kernel object that the operating system uses to manage the process. The kernel object is also where the system keeps statistical information about the process. An address space that contains all the executable or DLL module's code and data. It also contains dynamic memory allocations such as thread stacks and heap allocations.

Process It must have a thread that runs in its context; this thread is responsible for executing the code contained in the process's address space. A single process might contain several threads, all of them executing code "simultaneously" in the process's address space. Each thread has its own set of CPU registers and its own stack. Each process has at least one thread that executes code in the process's address space. If there were no threads executing code in the process's address space, there would be no reason for the process to continue to exist, and the system would automatically destroy the process and its address space.

DWORD WINAPI ThreadFunc(PVOID pvParam) { DWORD dwResult = 0;. return(dwResult); } Writing Your First Thread Function Entry-point function for your primary thread: main, wmain, WinMain, or wWinMain. If you want to create a secondary thread in your process, it must also have an entry-point function, which should look something like this:

The CreateThread Function HANDLE CreateThread( PSECURITY_ATTRIBUTES psa, DWORD cbStack, PTHREAD_START_ROUTINE pfnStartAddr, PVOID pvParam, DWORD fdwCreate, PDWORD pdwThreadID ); The system allocates memory out of the process's address space for use by the thread's stack. The new thread runs in the same process context as the creating thread.

Thread Synchronization With Kernel Objects The following kernel objects can be in a signaled or nonsignaled state: Processes File change notifications Threads Events Jobs Waitable timers Files Semaphores Console input Mutexes

Wait Functions DWORD WaitForSingleObject( HANDLE hObject, DWORD dwMilliseconds ); DWORD WaitForMultipleObjects( DWORD dwCount, CONST HANDLE* phObjects, BOOL fWaitAll, DWORD dwMilliseconds );

Memory Management Internally, a heap is a region of reserved address space. Initially, most of the pages within the reserved region are not committed with physical storage. When a process initializes, the system creates a heap in the process's address space. This heap is called the process's default heap. HANDLE GetProcessHeap();

Reasons to Create Additional Heaps In addition to the process's default heap, you can create additional heaps in your process's address space. You would want to create additional heaps in your own applications for the following reasons: Component protection More efficient memory management Local access Avoiding thread synchronization overhead Quick Free

How to Create an Additional Heap HANDLE HeapCreate( DWORD fdwOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize ); Allocating a Block of Memory from a Heap PVOID HeapAlloc( HANDLE hHeap, DWORD fdwFlags, SIZE_T dwBytes ); Freeing a Block BOOL HeapFree( HANDLE hHeap, DWORD fdwFlags, PVOID pvMem);

GetThreadTimes Function Retrieves timing information for the specified thread. BOOL WINAPI GetThreadTimes( __in HANDLE hThread, __out LPFILETIME lpCreationTime, __out LPFILETIME lpExitTime, __out LPFILETIME lpKernelTime, __out LPFILETIME lpUserTime );

CPU usage is generally represented as a simple percentage of CPU time spent on non-idle tasks. But this is a bit of a simplification. In any modern operating system, the CPU is actually spending time in two very distinct modes:CPU time spent on non-idle tasks Kernel Mode In Kernel mode, the executing code has complete and unrestricted access to the underlying hardware. It can execute any CPU instruction and reference any memory address. Kernel mode is generally reserved for the lowest-level, most trusted functions of the operating system. User Mode In User mode, the executing code has no ability to directly access hardware or reference memory. Code running in user mode must delegate to system APIs to access hardware or memory. Due to the protection afforded by this sort of isolation, crashes in user mode are always recoverable. Most of the code running on your computer will execute in user mode. Understanding User and Kernel Mode