The next topic that I want to cover is processes now, processes can get pretty complex, pretty quick.
So in this course, I would only be covering the basics of processes, and if I do make an intermediate
course, I'll be sure to go more in-depth with more complex topics and examples.
So first off, what is a process?
A process is essentially a program in execution.
And this program is able to be launched by other processes, and it is also able to launch other processes
itself.
And I will show you a diagram of that later.
Just as examples, I want to show you what Windows and Linux processes look like, so I'm going to head
over to my desktop first, and then we'll take a look at what Linux processes look like.
First off, here is what Windows processes look like.
This is found through going to the task manager.
And here you are able to see a list of all the processes currently running on your computer.
So as you can see here, I've Google run 19 tabs open OBS Studio.
There is something that looks like it's a window service, Cortana, virtual box and Windows Explorer
and a bunch more.
You're able to see how much CPU it's using memory, disk, network, CPU, etc..
So this is how you are able to view the processes in windows.
You can also right click and the task and also see other values and other important details.
Now that we are in my virtual machine, we could take a look at how Linux can display the processes
that are currently running on your machine.
You could do this by running the command post and as you can see it, only outputs two things.
And if you actually do a Dash A, it will print out every single process that is running.
So just going quickly over what each of these fields mean.
This first field is the process ID.
This is just given a unique ID to a certain process.
And this will be used later on in this course, and we'll be checking to see what the process IDs check
to see how long it's been running and etc..
Next, we have the too.I, which is the terminal associated with a certain process.
And as you can see, there are all just question marks.
And that's because all of these processes that are running were started from somewhere else.
There is no terminal that started it, but eventually we will be starting a program or a process.
I guess we'll call it now and it will be assigned to a certain terminal and that ID will be displayed
here.
Next, we have CMD, which displays the actual name of the process, and if there are any arguments,
they will be included here.
The next very important principle of processes is that a process is separate from all other instances
of that process.
And this is more related to memory mapping and because our operating system is doing some form of it,
to what extent it depends on your operating system and certain settings that you have configured.
But I will be showing you an example of that very shortly.
So here is an example of multiple instances, and this will show you the memory mapping.
OK.
To get started, I will just cover the general description of what this program hopes to accomplish.
This program will show you that if you have two instances of a program that they can share the same
virtual memory address at the same time, even if the data is different.
This program, you will be running with two arguments, and those arguments are just regular two integers.
So when we run our air out, we will pass in two integers.
From there, we'll go in an infinite loop where Prince Devalue Value one and value two of the two values
that you input it and also print the location of where that value is stored in memory.
I'm just going to show you at the start, and then we will go with more detail about what's actually
happening.
So to get started, we do our check.
And as you can see it out there.
And let's run it by doing either out and let's just pass in to numbers like 12 and 16.
So this will be running in an infinite loop for a little bit.
As you can see, Value one is staying at 12 and Value two is staying at 16.
When you look at the location for Value one, it is staying at 555 seven five eight zero one eight.
And when you look at the value two, it is staying at five zero one four.
So now let's open up another terminal window and go ahead and run the exact same program.
Except now let's pass in different values and we will see how it is actually working.
Let's passing in not twelve fifty one eighty one.
As you can see, the values are pointing at fifty one.
The whole time value to our putting is eighty one, as we expected.
But however, when we look at our location, it is the exact same location that is used in the other
instance of the program.
So the question comes down to how exactly is this possible and why?
How can they share the exact same location if these are two separate programs running at the exact same
time?
There is a thing in Linux today that you can enable, it's called address space layout randomization.
This will make your memory address harder to predict when someone is trying to say to a memory, corruption,
exploit or stuff along those lines.
So currently, in some Linux distros, this comes off by default and you have to turn it on.
So I'm going to do another example where I turn asla on and you'll see that actually different locations.
But in this sense, here, let me just say that right now they are, they're able to share the same
virtual memory just at the same time, but not the same physical memory address.
So if were right now, it looks like they're sharing the same address.
They're actually not.
Each program is running in its own memory space, so the address you see here is actually not the real
physical address.
These two instances of programs are not seeing each other, but they believe that they are using the
same address.
That's more of looking at virtual memory addresses.
So if we go a little more in depth and take a look at if we are able to change this variable, which
is the SLR, if we go ahead and enable that, which is setting it to two.
And if you guys have questions about what exactly this command is doing, I will be more than happy
to make a whole lecture on it.
But this is more of something behind the scenes that I want to explain about processes before we move
into further topics.
And that is that the virtual memory address might be the same, but the actual physical is not.
So now let's go ahead now that we enabled SLR, which will help us randomize our our memory addresses
randomization, we will see that they do not share the same memory just as so let's go ahead and run
the exact same program.
And as you can see, they are located at different memory addresses.
Now this is located at 56.
This is kind of 55, 56, 55.
So that is something that I think is pretty cool.
That is something you have to keep in mind because sometimes you think that the two programs are accessing
the same memory location, but they're actually not.
So let's head over back to the slide deck and move on.
Another important aspect of processes is that they have different states and you have to understand
when they are leaving states or coming to states and what is actually driving these events to change.
But just get started, I will discover what each of the states are and they will go more in-depth in
later courses.
The first state is the start state.
This state is the initial state when a process is created and started.
And once it is start, it is admitted into a ready state.
This ready student ready state is basically waiting for this process to be assigned to a CPU.
And so it depends on how many cores you have.
You can move on from there to other states.
As you can see from the ready state, you are able to move to the running state.
If you are scheduled through a schedule dispatcher, so once you are signed to a CPU by the process
schedule of the operating system, the process is now in a running state and the CPU is executing it.
However, when it is it, when it is in this state, it is able to do things.
It is able to go back to being in the right state if an interrupt occurs and we can go into more detail
about interrupts later.
If you'd like or from that running statement, it can go to the terminated state, which is the exit,
and this terminated state occurs after it's finished, finished executing and it basically waits here
to be removed from memory.
Running back to the waiting state, as you can see, it can be waited and it can move to the running
state or the ready state, waiting is basically here.
If this process is waiting for something to occur, some event this event can be anything such as waiting
for information from other processes, waiting for a CPU.
It could be waiting for user input, etc. So once it gets what it needs, it is able to go to running
state or the ready state.
And if you like me to go more in depth about how process scheduling works, including different scheduling
algorithms, then let me know when I can make a separate video on that, because that is a very heavy
topic on different process scheduling and how they're brought into the queue, depending on certain
factors.
The scheduler basically schedules processes to be executed.
If one processor in the system, then one processor will be executed fine.
If there are multiple processors in the system, then multiple processes can be executed at the same
time.
This process scheduler picks and chooses which processes to run, and these processes may be stopped.
They may be completed, or they may be stopped to run another process if it has a higher priority,
et cetera.
There is a lot to it, and if you run a program that creates multiple processes, you do not know what
order they will be executed in.
This is something we will cover in this course.
You can create a program and you think that it might run one way, but you don't know how the schedule
is going to be handling the multiple processes and they can execute in any order.
So you could go process one two three four.
But if you run it again in my executed process to first process for second and so on, so that's something
to consider.