processes and threads microsoft. process process model process creation process termination ...
DESCRIPTION
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?TRANSCRIPT
Processes and Threads
MICROSOFT
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
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?
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:-
• Process is an activity of some kind.
Process
Program Input Output State• 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.
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:-
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
In Unix ----- forkThis 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, directlyor 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
Creation Loading
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.
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 – WindowsScreen-oriented programs also support voluntary termination
Fatal Error:cc foo.cScreen-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.
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:-
new
Enter
Ready
Admit
Running
Dispatch Time-Up
Blocked
I/O Request
I/O Completion
(wake up)
Halted
TerminateHalt/Kill
Process States and it’s Transitions:-
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:
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:-
Per process items Per thread items Address spaceGlobal variablesOpen filesChild processesPending alarmsSignals and signal handlersAccounting information
Program counterRegistersStackState
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.
Each thread has its own stack
2. Thread_exit3. Thread_wait
4. Thread_yield
1. Thread_Create
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.
There are two main ways to implement a threads package: 1. User Space2. Kernel Space
Implementing Threads in User Space and Kernel Space:
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.
Pop-Up Threads
Creation of new thread when a message arrives. (a)Before the message arrives. (b) After the message arrives .
Making Single-Threaded Code Multithreaded:
Code of a thread normally consists of multiple procedures just like a process.
1. Local Variables2. Global Variables3. 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”.
Threads having private global variables:
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.