Presentation is loading. Please wait.

Presentation is loading. Please wait.

Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread.

Similar presentations


Presentation on theme: "Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread."— Presentation transcript:

1 Processes and Threads MICROSOFT

2  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread  Thread Model  Implementation of Threads in user space  Implementation of Threads in kernel Space  Pop-Up Threads  Making Single Threaded code multithreaded Agenda

3  Process is an instance of program that is being executed.  It contains the program code and its current activity.  Depending on the Operating System(OS), a process may be made up of multiple threads of execution that execute instructions concurrently.  Parallelism What is a Process?

4  In this model, all the runnable software on the computer, sometimes including the operating system, is organized into a number of sequential processes.  A process is just an executing program, including the current values of the program counter, registers, and variables.  CPU switches back and forth from process to process, but to understand the system, it is much easier to think about a collection of processes running parallel.  The rapid switching back and forth is called multiprogramming. Process Model:-

5 Process is an activity of some kind. Process ProgramInput OutputState A single processor may be shared among several processes, with some scheduling algorithm being used to determine when to stop work on one process and service a different one.

6 Four Principle Events that cause processes to be created: 1. System initialization. 2. Execution of a process creation system call by a running process. 3. A user request to create a new process. 4. Initiation of a batch job. Process Creation:-

7 Processes that stay in the background to handle some activity such as email, Web pages, news, printing, and so on are called daemons. Foreground Processes Background Processes Processes that interact with users Not associated with particular user, they have some specific function

8 In Unix ----- fork This call creates an exact clone of the calling process. UNIX:- System Call: System call tells the operating system to create a new process and indicates, directly or indirectly, which program to run in it. Usually, the child process then executes execve or a similar system call to change its memory image and run a new program. WINDOWS: CreateProcess Win32 function call CreationLoading

9 CreateProcess This call has 10 parameters which include:- Program to be executed The command line parameters to feed that program Various security attributes Bits that control whether open files are inherited A specification of the window to be created for the process (if any) A pointer to a structure in which information about the newly created process is returned to the caller. In both UNIX and Windows, after a process is created, both the parent and child have their own distinct address spaces.

10 1.Normal exit (voluntary). 2.Error exit (voluntary). 3.Fatal error (involuntary). 4.Killed by another process (involuntary). Process Termination:- Normal Exit: Exit – Unix ExitProcess – Windows Screen-oriented programs also support voluntary termination Fatal Error: cc foo.c Screen-oriented interactive processes generally do not exit when given bad parameters. Instead they pop up a dialog box and ask the user to try again.

11  When a process creates another process, the parent process and child process continue to be associated in certain ways.  The child process can itself create more processes, forming a process hierarchy.  Windows does not have any concept of a process hierarchy. All processes are equal.  The only place where there is something like a process hierarchy is that when a process is created, the parent is given a special token (called a handle) that it can use to control the child. Process Hierarchies:-

12 new Enter Ready Admit Running Dispatch Time-Up Blocked I/O Request I/O Completion (wake up) Halted Terminate Halt/Kill Process States and it’s Transitions:-

13 What is a Thread? A thread is a single sequence stream within a process. Threads have some of the properties of processes, they sometimes called as, Lightweight processes. multiple executions of streams THREADS:

14  The process model is based on two independent concepts: resource grouping and execution. Sometimes it is useful to separate them; this is where threads come in.  The other concept a process has is a thread of execution, usually shortened to just thread.  The thread has a program counter that keeps track of which instruction to execute next.  Registers  Stack Thread Model:-

15

16 Per process itemsPer thread items Address space Global variables Open files Child processes Pending alarms Signals and signal handlers Accounting information Program counter Registers Stack State The first column lists some items shared by all threads in a process. The second one lists some items private to each thread. In addition to sharing an address space, all the threads share the same set of open files, child processes, alarms, and signals, etc.

17 Each thread has its own stack 2. Thread_exit 3. Thread_wait 4. Thread_yield 1. Thread_Create

18 Processes Vs Threads: Similarities  Like processes, threads share same CPU and only one thread (active) running at a time.  Like processes, threads within a processes execute sequentially.  Like processes, threads can create children.  If a thread is blocked, another thread can run. Differences  Unlike process, threads are not independent of one another.  All threads can access every address in the task.  Thread are designed to assist one another.  Note that processes might or might not assist one another because processes may originate from different users.

19 There are two main ways to implement a threads package: 1. User Space 2. Kernel Space Implementing Threads in User Space and Kernel Space:

20 Hybrid Implementations:- -- Various ways have been investigated to try to combine the advantages of user-level threads with kernel-level threads. One way is use kernel-level threads and then multiplex user-level threads onto some or all of the kernel threads Multiplexing user-level threads onto kernel-level threads.

21 Pop-Up Threads Creation of new thread when a message arrives. (a)Before the message arrives. (b) After the message arrives.

22 Making Single-Threaded Code Multithreaded: Code of a thread normally consists of multiple procedures just like a process. 1. Local Variables 2. Global Variables 3. Procedure Parameters Errno is a variable maintained by UNIX When a process/thread makes a system call that fails, The error code is put in to “Errno”.

23 Threads having private global variables:

24 First Call: create_global("bufptr"); Two calls are needed to access global variables: one for writing them and the other for reading them. For writing, set_global("bufptr", &buf); It stores the value of a pointer in the storage location previously created by the call to create_global. To read global Variable, bufptr = read_global ("bufptr"); It returns the address stored in the global variable, so its data can be accessed.


Download ppt "Processes and Threads MICROSOFT.  Process  Process Model  Process Creation  Process Termination  Process States  Implementation of Processes  Thread."

Similar presentations


Ads by Google