Process and Memory Management in Operating Systems
Resource Management
Processes and Flows
- Def Process: Program in execution.
- Homepage More names:
- Control-Flow
- Tasks
- Threads (I will comment with a Java language example)
- Thread (of execution)
- The Operating System (OS) assigns a data structure (BCP) to all processes.
- What does the BCP contain?
- Current status
- Process Identifier
- Process priority
- Location in memory
- Resources used
Thread and States of Processes
- Def Thread: Point of execution of a process (a process can have one or more threads).
- Example: Word running (1 process) opening 1 document (1st thread), opening a 2nd document (2nd thread).
- States of a process:
- Running on CPU
- Ready (waiting, active)
- Blocked (withheld), for example, waiting for a resource to be free (DVD player, …)
- Additional Comments:
- Any activity has a Process ID (PID). (already discussed in paragraph 3.1)
- A running process may need (create) other processes (children). It has a Parent Process ID (PPID).
Transition of Processes
- Question: Can a process change state? Answer: Yes
- Consider the changes (transitions) in Figure 3.2 on page 56. (Study it, the explanatory text is next to its lower part).
- Additional comments:
- If a process (or thread) changes state, it’s called a context switch.
- If the change is between threads of the same process, it’s a partial context switch (if between threads of different processes, it’s a complete context switch).
- State changes are directly related to the priorities between processes.
Who handles all this?
Answer: The scheduler, using a scheduling process execution mechanism. Priority assignment is done by a scheduling algorithm. -> Quantum.
BCP
Read about BCP.
Scheduling Algorithms
- Round-Robin Algorithm:
- Each process is assigned the same amount of run time (quantum).
- The choice between processes is FIFO (First In, First Out).
- Example: CPU P1 -> P2 -> P3 -> quantum = 5 ms
- FCFS Algorithm (First Come, First Serve):
- It also uses a FIFO queue.
- It starts a process, and only when it finishes, it starts the next one, and so on.
- STR Algorithm (Shortest Time Remaining):
- Prioritizes processes that are short, with the idea of finishing them soon.
- SRTF Algorithm (Shortest Remaining Time First):
- Prioritizes the one that has the least time remaining to finish.
RAM and Virtual Memory
Virtual Memory: Concept introduced in 1961 (Fotheringham). It consists of using part of the secondary memory as RAM (virtualization).
Problem: The lower speed of secondary memory causes slowdowns.
Question: Can I assign all (almost all) of the secondary memory as RAM?
Exchange
- If a process needs to enter into memory:
- The scheduler requests memory from the Memory Manager.
Fixed partitions, Variable partitions. Techniques: Paging, External Segmentation.
Paging, Segmentation, Swapping
Paging
- Divide:
- RAM into frames
- Processes into pages
- We place the various pages in frames.
- We will need:
- A page table
- A page manager
Segmentation
- We define blocks of varying size but with a maximum allowable size.
- Technique used in processor architecture (design), which divides the running program into 4 blocks:
- CS (Code Segment)
- DS (Data Segment) Each segment corresponds to an internal CPU register.
- ES (Extra Segment)
- SS (Stack Segment)
Classification of Programs
(Depending on how, when, and where they are located in memory)
- Relocatable: They can change position in RAM if necessary.
- Re-entrant: If they can, they don’t need to go to disk (virtual memory).
- Resident: Permanently stay in memory (e.g., antivirus).
- Reusable: Used by more than one user at a time.