Lecture 4
Process Scheduling, Operations, and Creation
When a Process is scheduled, this means a program has now shifted from a passive entity to an active entity.
A way to understand the process schedule is through a Queuing Diagram. These represent the queues, resources, and flow of an operating system. (See below for an example)
Process Schedulers
There are different kinds of schedulers involved in Operating Systems
Short-term Scheduler (or CPU Scheduler) - This is a scheduler selects process loaded into the ready queue that are waiting to execute and allocated them to the CPU.
This maintains a context switch
This can be the only scheduler in a system
This scheduler is frequently invoked by the system (milliseconds) Thus is needs to be fast
Long-term Scheduler (job Scheduler) - This is a scheduler takes processes from a job pool and manages them. These processes should be things loaded into the ready queue.
It maintains queue of programs/jobs which are selected for system to process
This controls the degree of multi programming.
Degree of multi programming - describes the number of processes that a single processor system can accommodate efficiently.
This scheduler is invoked infrequently (Seconds or Minutes) and thus may be slow.
Medium-term Scheduler - This will execute swapping
Swapping - Remove process from memory, store on disk and bring back in from disk to continue execution.
These Processes can be described as either
I/0 bound Process - This processes dedicates more time to I/O processes, such as listening to user input, rather than other computations.
Many short CPU bursts
In IDEA, they're the people interacting directly with the customers, but they just deliver messages to people in the back.
CPU bound Process - This process dedicates more time to computations, with very few CPU bursts
In IKEA, they're the people in the back doing all the computation.
Long term Scheduler strives for good process mix of both I/O bound and CPU bound processes.
Operations on Processes
For a give system, it must provide mechanisms for:
Process creation
Process Termination
Process Creation
Process creation is similar to nodes and their functionalities in CPS 151 and 350
Parent - Creates processes
Children - the processes created by children
When multiple Parent processes create children processes, this forms a Tree of processes
To differentiate between processes, they are identified and manages vai a Process identifier (pid)
Think of this PID like a pointer in CPS 250, that points to a given line of the program and will remember those lines. The PID is unique for a given process, and no two processes can have the same pid
In terms of parent child process resource sharing OPTIONS, Parent and children can
Share all of their resources
share subset of parent's resources
Share none of their resources
Execution options for parent children processes are:
execute concurrently
Parents waits until untimely death (termination) of their children.
Address Space
Child is a duplicate of a parent.
The child has a program loaded on it.
Idea of how a Tree Processes work and connect
Fork(): Make baby processes
What Is Fork() (what's forking()?)
Fork creates little baby child processes from existing processes.
The child process gets new PIDs
If it's taking too long, you might need to kill it.
Control Flow of Forking
How to Fork
Use the fork() to create a new process
Running Different Functionality
Forks can
Exec(): Make one process run another program.
exec()
Exec is a family of function calls on linux operating systems
When you call Exec, it doesn't create a child. It replaces the current process.
The program that was running ceases to exist.
execlp()
V stands for vectory, meaning you pass in the arguments as a vector, or array.
If you add the p, then that means you're going to do path searching. You will search for the ls program you're going to run.
E means you're going to pass in new environment variables. If you don't specify them, the original environment variables are going to be passed into it
The process list needs to be NULL terminated so it knows there are no more arguments.