Doubt – Program Vs. Process • A process invokes or initiates a program. It is an instance of a program that can be multiple and running the same application. • Example:- Notepad is one program and can be opened twice. • A process is a sequence of tasks. 1/9/2014 Computer Engineering Department - MEFGI 4

Process • Daemons: processes that are running in the background mode (e.g. checking email) • The only Unix system call to create a new process is fork. After that new process has same memory image, same open files and etc. as its (only one) parent • kill is the system call to terminate a process • In Unix all the processes in the system belong to a single tree, with init at the root 1/9/2014 Computer Engineering Department - MEFGI 9

Process States • As a process executes, it changes state – new: The process is being created. – running: Instructions are being executed. – waiting: The process is waiting for some event to occur. – ready: The process is waiting to be assigned to a processor. – terminated: The process has finished execution. 1/9/2014 Computer Engineering Department - MEFGI 10

Process Implementation • Process table is used to maintain process information ( one for each process ) • Process table is array of structure • Another name for process table is process control block (PCB) • PCB is the key to multiprogramming • PCB must be saved when a process is switched from running to ready or blocked states 1/9/2014 Computer Engineering Department - MEFGI 13

Review In theory, with three states, there could be six transition, two out of each state. However, only four transitions are shown. Are there any circumstances in which either or both of the missing transitions might occur? 1. 2. 1/9/2014 The transition from blocked to running is conceivable. Suppose that a process is blocked on I/O and the I/O finishes. If the CPU is otherwise idle, the process could go directly from blocked to running. The other missing transition, from ready to blocked, is impossible. A ready process cannot do I/O or anything else that might block it. Only a running process can block. Computer Engineering Department - MEFGI 17

Review • Suppose that you were to design an advanced computer architecture that did process switching in hardware, instead of having interrupts. What information would the CPU need? Describe how the hardware process switching might work.  You could have a register containing a pointer to the current process table entry. When I/O completed, the CPU would store the current machine state in the current process table entry. Then it would go to the interrupt vector for the interrupting device and fetch a pointer to another process table entry (the service procedure). This process would then be started up. 1/9/2014 Computer Engineering Department - MEFGI 18

Thread - Motivation • Threads are very useful in modern programming whenever a process has multiple tasks to perform independently of the others. • This is particularly true when one of the tasks may block, and it is desired to allow the other tasks to proceed without blocking. • For example in a word processor, a background thread may check spelling and grammar while a foreground thread processes user input ( keystrokes ), while yet a third thread loads images from the hard drive, and a fourth does periodic automatic backups of the file being edited. 1/9/2014 Computer Engineering Department - MEFGI 19

Thread • Each process has a single address space that contains program text, data and stack. Multiple threads of control within a process that share a same address space are called threads. • Threads are lightweight processes that have their own program counter, registers and state. • Threads allow multiple executions to take place in the same process environment. • Multiple threads running in parallel in one process share program address, open files and other resources. Multiple process running in parallel in one computer share physical memory, disk and printers. 1/9/2014 Computer Engineering Department - MEFGI 20

Threads Items shared by threads in a process Items private to each thread

Threads • Threads in three process (a) and one process (b)

Multi - Threading • Multithreading is the ability of a program or an operating system process to manage its use by more than one user at a time and to even manage multiple requests by the same user without having to have multiple copies of the programming running in the computer. 1/9/2014 Computer Engineering Department - MEFGI 23

More Details 1/9/2014 Computer Engineering Department - MEFGI 24

1/9/2014 Computer Engineering Department - MEFGI 25

How Sharing Will Work Achieves concurrency without the overhead of using multiple processes Threads within the same process can exchange information through their common address space and have access to the shared resources of the process Threads in different processes can exchange information through shared memory that has been set up between the two processes

Advantages of Thread • Responsiveness - One thread may provide rapid response while other threads are blocked or slowed down doing intensive calculations. • Resource sharing - By default threads share common code, data, and other resources, which allows multiple tasks to be performed simultaneously in a single address space. • Economy - Creating and managing threads ( and context switches between them ) is much faster than performing the same tasks for processes. 1/9/2014 Computer Engineering Department - MEFGI 27

One More Advantage • Scalability i.e. Utilization of multiprocessor architectures - A single threaded process can only run on one CPU, no matter how many may be available, whereas the execution of a multi-threaded application may be split amongst available processors. ( Note that single threaded processes can still benefit from multi-processor architectures when there are multiple processes contending for the CPU, i.e. when the load average is above some certain threshold. ) 1/9/2014 Computer Engineering Department - MEFGI 28

Types of Thread • There are two types of threads to be managed in a modern system: User threads and kernel threads. • User threads are supported above the kernel, without kernel support. These are the threads that application programmers would put into their programs. • Kernel threads are supported within the kernel of the OS itself. All modern OSes support kernel level threads, allowing the kernel to perform multiple simultaneous tasks and/or to service multiple kernel system calls simultaneously. 1/9/2014 Computer Engineering Department - MEFGI 29

Review • On all current computers, at least part of the interrupt handlers are written in assembly language. Why? • Generally, high-level languages do not allow one the kind of access to CPU hardware that is required. For instance, an interrupt handler may be required to enable and disable the interrupt servicing a particular device, or to manipulate data within a process’ stack area. Also, interrupt service routines must execute as rapidly as possible 1/9/2014 Computer Engineering Department - MEFGI 30

Review • Can a thread ever be preempted by a clock interrupt? If so, under what circumstances? If not, why not? • User-level threads cannot be preempted by the clock unless the whole process’ quantum has been used up. Kernel-level threads can be preempted individually. In the latter case, if a thread runs too long, the clock will interrupt the current process and thus the current thread. The kernel is free to pick a different thread from the same process to run next if it so desires. 1/9/2014 Computer Engineering Department - MEFGI 31

Review • In a system with threads, is there one stack per thread or one stack per process when user-level threads are used? What about when kernel-level threads are used? • Each thread calls procedures on its own, so it must have its own stack for the local variables, return addresses, and so on. This is equally true for user-level threads as for kernel-level threads. 1/9/2014 Computer Engineering Department - MEFGI 32

Thanks “I know what I have given you... I do not know what you have received.” 1/9/2014 Computer Engineering Department - MEFGI 33

Please help. Sophos is failing to update. - Sophos ...

These presentations are classified and categorized, so you will always find everything clearly laid out and in context.
You are watching Writing the thesis statement:A part of your doctor... presentation right now. We are staying up to date!