Sunday, November 25, 2007

Guide to Operation System Part 5

Process
A Process is a binary program in execution.
A Process consists of:
- A binary Program
- Data on which the program will execute
- Resources required for execution ( e.g. files, devices which contains or provides the data)
Note: In classic process design, there is only one execution engine for each process. In another word, there is only one thread in a process. However, modern process can consist of multiple execution engines.

Thread
A Thread is a single execution engine capable of performing a series of instruction.
Note: In a multiple Threaded process, each thread needs to maintain its own set of data in order to perform its own series of instructions.
Thread specific data is private to the thread. This data is usually stored in a stack.

A Thread data consists of:
- Program counter
- Status of the thread
- Processor registers
- Stack space

Threads Within the same process shares the same:
- Program code
- Data
- Resources

Note: Sometimes threads are also called lightweight processes.
Process in UNIX

OS Kernel creates a process descriptor to manage process.
Process identifier (PID): User handles for process (descriptor)

Benefits of Multithreaded programming:
- Responsiveness
- Resources Sharing
- Economy
- Utilization of multiprocessor architectures

Process Descriptor
OS creates/manages process abstraction
Descriptor is data structure for each process
- Process ID
- Program counter
- Register values
- Process state
- Type and Location of resources it holds
- List of resources it need
- Security keys
Also known as Process Control Block (PCB)

Context Switching (Itself is a overhead but is a necessity to switch between processes)
When CPU switches between two processes/threads, it is called context switch.
A context switch can only occur when the OS gets control of the CPU through traps or interrupts.

Process States
- Running: Instructions are being executed
- Blocked: The process is waiting for some event to occur ( e.g. I/O completion)
- Ready: The process is waiting to be assigned to a processor
- Done: The process has finished execution

Posted by Zack at 5:29 PM