Lecture 3: Processes
Concepts of Process
A process (Job) is a an active entity in which a program is running. This differs from a program as a this is a passive entity stored on a disk or executable file, it is the code itself that has yet to run.
For instance, say you have a Dolphin emulator and you can retrieve games from emuparadise vs CoolROMs. All the files on these websites are just programs, passive entities. However, if you did not do your research, when you unzip the downloaded passive program and run it, it becomes an active entity (process), and will either play the a game or give you a virus. ¯\_(ツ)_/¯
Types of programs OS executes
Batch System - Jobs
This system does not interact with the computer directly. It takes jobs of the same requirement and groups them in a batch to be done at the same time by the CPU
For More Information on Batch Processing:
Time-Shared System - User Programs or tasks
It is as it sounds like. Each task gets an equal opportunity to perform its task under the same time period.
There are Multiple parts to a process
Text section - program's code
Program Counter - monitors activity occurring in the program, and keeps track of which line is being executed
Stack - contains temporary data of a program
ie function parameters, return addresses, local variables
Data section - global variables
Heap - dynamically allocated memory during runtime
Bigger in size and relatively slower
Dynamic allocation of memory is created because user or programmer is unsure of the amount of memory needed for the program before running
This could include creating arrays to hold values until a larger array can be created
A Program moves from being a passive entity to a process when the program is started via user input
GUI mouse clicks, cmd line, etc.
A program can be several processes and it is important to consider multiple users executing the same program, such as online gaming or D&D and Beyond (ask Later)
Process in memory
The space in between stack and heap is a shared library region. In addition to API used by program, it is room for the stack to grow down or heap to grow up without risking running out of memory
This was taught briefly in CPS 151, and More in depth in CPS 350
Process State
As the Process executes in a system, there are various states the process can enter
New - Process is being created
Ready - A process is waiting to be assigned to the processor
Running - Instructions are being executed
Waiting - Process is waiting for an event to occur
Terminated - The process has finished execution
Example: Think of a video game and how there are different states. There is the start game state where you start a new file as a character, there is a menu where, depending on the game (jklj Blood borne) it stops the other processes on the screen from moving, a save state, and an end game state.
Note: I will add details about slide 3.7 later
Process Control Block (PCB)
Also known as the Task Control Block , the PCB is a Data structure created for each process, and includes all information about the process.
Parts of the PCB include
***Process State - Running, Waiting, terminate, etc.
***Program Counter - Location of instructions that is to execute next
Holds address of the next instruction to be executed in the process
***Process ID - What Process is running at the time and sees what the Parent Process ID is if it has a parent
CPU registers - contents of all process-centric registers
CPU Scheduling Information - priorities scheduling queue pointers
Memory-management Information - memory allocated to the process
Accounting Information - CPU used, clock time elapse since start, time limits
This Includes the User and Kernel operations
I/O Status Information - I/O Devices allocated to process, list of open files
For More information: https://www.youtube.com/watch?v=Ea63gRbEgkw
Threads
A Thread is a process / flow of execution.
However, if there are multiple program counters per process, there are more threads.
To have multiple program counters, it means there are multiple locations of a process that can be executed at once. Thus there are multiple threads to control hence the term "threads"
For a general example (not exact), GOland has a function called go routines. It means that multiple process can run parallel to each other. Say these processes all contribute to an overall objective, it can be compared to threads
<--- CPU Switching Processes
Context Switch
In order a CPU to switch Processes, a context switch is used.
A context switch, while costly, has the system save the state of the old process and load a saves state of the new process. This, I am assuming, is related to interrupts and how they switch between processes
Context of a process is represented in the PCB
Note: The system foes not do useful work while switching. If it could, there would be no use for a context switch.
the More complex the OS and PCB means the longer the context switch
The time for a context switch to occur is dependent on the hardware suppose
Are there multiple registers per CPU, which means there can be multiple contexts loaded at once\
A short video: https://www.youtube.com/watch?v=lS1GOdXFLJo
Process Scheduling
A schedule is needed to to maximize and optimize CPU use. It is what handels removing processes once execute or elapse of time and moving new processes to the CPU.
The process Scheduler maintains scheduling queues of processes
Job Queue - set of all processes in the system
Ready Queue - set of all processes residing in the main memory, ready and waiting to execute
Device / Block Queue - set of processes waiting for an I/O device
For more information: https://www.tutorialspoint.com/operating_system/os_process_scheduling.htm#:~:text=Definition,of%20a%20Multiprogramming%20operating%20systems.