[OS] Process 1
Updated:
Process Part 1
Process
- An instance of program in execution
- Program becomes process when executable file loaded into memory
- Program is passive entity stored on disk, process is active
- One program can become several processes (consider multiple users executing the same program)
- Each process is identified using its process ID (PID)
From program to process
- Each process has its own address space in memory
- The program code, also called text section
- A register called Program Counter(PC) points to the instruction that is currently executing
- Data section containing global variables
- Stack containing temporary data
- Function parameters, return addresses, local variables
- Pointed by Stack Pointer (SP) register
- Heap containing memory dynamically allocated during run time
Process State
As a process executes, it changes state
- new : The process is being created ( by fork() )
- running : Instructions are being executed
- waiting : The process is waiting for some event to occur ( queue )
- ready : The process is waiting to be assigned to a processor ( queue )
- terminated : The process has finished execution
Process Control Block (PCB)
- Information associated with each process (also called task control block)
- Each PCB represents a process (loaded on main memory)
- Process state : running, waiting, etc …
- Program counter : location of the instruction to execute next
- CPU registers : contents of all process
- CPU scheduling information : priorities, scheduling queue pointers, etc …
- Memory managment information : memory allocated to the process
- Accounting information : CPU used, clock time, etc …
- I/O status information : I/O devices allocated to process, list of open files, etc …
Context Switch
- Context of a process represented in the PCB
- When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process using a context switch
- The system does no useful work while switching
- The more complex OS and the PCB, the longer the context switch (longer latency)
- Time dependent on hardware support
CPU switch
- Cpu do nothing while context switching
Threads (detail in CH4)
- Process has a single thread of execution
- All program have at least one thread
- Multiple threads
- operate independently
- program counter(PC) exist per thread
- 1 PCB exist (1 process)
Process Scheduling
- Goal : Maximize CPU use, quickly switch processes onto CPU for time sharing
- Process scheduler selects among available processes for next execution on CPU
- Maintains scheduling queues of processes
- Job queue : set of all processes in the system
- Ready queue : set of all processes residing in main memory, ready and waiting to execute
- Device queue : set of processes waiting or an I/O device
Schedulers
- Short-term scheduler (CPU scheduler)
- selects which process should be executed next and allocates CPU
- sometimes the only scheduler in a system
- invoked frequently, so must be fast
- Long-term scheduler (job scheduler)
- selects which processes should be brought into the ready queue
- invoked infrequently, so may be slow
- Processes can be described as either:
- I/O bound process: spends more time doing I/O than computations
- CPU bound process: spends more time doing computations
- Long-term schedulers strives for good process mix of I/O and CPU bound jobs(make all busy)
- Medium-term scheduler (multiple programming)
- Remove process from memory, store on disk, bring back in from disk to continue execution (swapping)
Leave a comment