One of the most important tasks that
our kernel performs is process management.
A process is a program that's executing,
like our Internet browser or text editor.
A program is an application
that we can run, like Chrome.
Take note of the difference.
We can have many processes of
the same program running at the same time.
Think of how many Chrome windows you can open.
These are all different processes for the same program.
When we want to run our programs,
we have to dedicate computer resources to them,
like RAM and CPU.
We only have a finite amount of resources,
and we want to be able to run multiple programs.
Our kernel has to manage our resources
efficiently so that all the programs
we want to use can be run.
Our kernel doesn't just dedicate
all of our computers resources to one process.
Our system is actually constantly running
multiple processes that are necessary for it to function.
Our kernel has to worry about all of
these processes at once.
What a program wants to run,
a process needs to be created for it.
This process needs to have
hardware resources like RAM and CPU.
The kernel has to schedule time for the CPU to
execute the instructions in the process,
but there's only one CPU and many processes.
How is the CPU able to execute
multiple processes at once? It actually doesn't.
It executes processes one-by-one
through something known as a time slice.
A time slice is a very short interval of time that
gets allocated to a process for CPU execution.
It's so short that you don't even notice it.
It's super short.
The CPU executes one process in milliseconds,
then executes another process, then another.
To the human eye, everything looks
like it runs simultaneously.
That's how fast the CPU works.
If your computer is running slowly,
and your CPU resources are being maxed out,
there can be many factors at play.
It's possible that one process is
taking up more time slices than it should.
This means that the next process can't be executed.
Another possibility is that
there are too many processes that
want CPU time and the CPU can't keep up with them.
Whatever the case may be,
even though the kernel does its best
to manage processes for us,
we might need to step in manually from time-to-time.
The kernel creates processes,
efficiently schedules them, and
manages how processes are terminated.
This is important since we need a way to collect
all the previously used resources that
active processes were taking up
and reallocate them to another process.