Everybody and welcome to the next video in the Linux operating system module.
Now this video we're gonna be going over Linux processes and how they work.
So what is the Process.
Process is a program or an application that is in execution currently.
This is also known as an instance of a running application.
Now an example of this this stuff is every time we type unless we were creating a new process and then
the process was stopping or exiting when it was done.
So every time we run a command we are generating what's called a foreground process which I'll go over
in a second just understand that processes always or processes always run in the background in the foreground
and I'll explain that now.
So there's two types the foreground process is what we talked about so the terminal is a foreground
process a web browsers a foreground process us running LSI is foreground.
Anything we interact with is a foreground process now background process known as a non interactive
process is not normally connected to any foreground process at all and doesn't usually expect user input
such as the process that handles the keyboard the mouse.
Let's say you're running a web service it doesn't require any user input normally to run the process
so it sits in the background now creating a process.
This is again normally done by running the binary and for programmers out there it's normally done with
the system fork or exact system call for our instances we don't need to go over those three specifically
we'll get we'll touch base on those pretty heavily in further modules just understand that creating
the process can be done from just running something or spawning something as a copy of itself which
will go over now.
So when we identify a process it gets something called a p idea or a process.
This is a unique number that the kernel uses to keep track of the current process.
So in a multi-user system we might not be the only ones running at less at that particular time or running
tail to watch a log file.
You don't want the two getting mixed up with each other so they're assigned a process I.D. which keeps
them unique between the two individual users or a thousand users.
When an application is first ran it's considered a parent and that will have its its regular API.
However when it uses something called fork as an example and it spawns a copy of itself it gets a PIV
and a PPD which is the parent I.D. so it knows what process it was attached to.
Normally when you kill the parent or stop the parent process it will stop all of the child processes.
That's what this is called.
So it's important to understand the difference between a process and a child process when looking at
processes in a general standpoint.
Now there is a top level process or a mother process.
This is started by the kernel itself when it first boots.
Now this will have a PIB of number one in most cases.
This is the in IT process.
However in newer systems it can be System D depending on how they are running it now.
All processes on the system are a child of PD 1 whatever that executable actually is.
It's a it's always a child process process of that because it's the parent's job is to manage all of
the child's and this goes further downhill.
Like I said when you're taking a standard executable and you're running it and it spawns a copy of itself
the parent is in charge of the of the child.
So in this case it's the same it's the same thing the parents in charge of killing killing off the child.
Process if it if it needs to or stopping it pausing it whatever the case might be.
Now there are four states of a process.
Is running waiting stopped and then the zombie slash orphan stage some sometimes people call it Orphan
it's normally referred to as a zombie.
But when you hear somebody say it's an orphan process you know that it's a zombie.
Now the state of running is just pretty standard.
It's either actively running or waiting for a CPA court cuarto assigned to it.
Now the way this works is it's everything can't run at the same time regardless of what it looks like
it's happening.
So an application needs to have access to a few core to actually perform functions.
Now there's only so many cores on the system so only so many things can technically be quote running
at a time so it'll still show a state of running.
However it might still be waiting for CPA time essentially to be able to perform its actions.
The problem the state of waiting now this is normally one of two things the waiting for one or two things.
It's either the user input or some other input it's waiting for such as a file or this.
Again the system resources to become available whether there's a file that there's too many file descriptors
open which will go over later just any any type of resource to be available or some sort of input such
as user input or from another application maybe.
And then there's two types of this particular process there's the interrupted and uninterrupted now
interrupted is the normal state of of a waiting process it's waiting on some sort of hardware condition
maybe it's waiting for you time a little bit longer than normal and the uninterrupted one is something
a process that cannot be stopped by an event such as user input or resource waiting or a signal which
will go over in a little bit actually we'll touch on it now.
So a signal is a type of command.
That's process is sent to do something such as I want to signal this process to go into the background
instead of being in the foreground you can do that signaling it to going from background to foreground
you can do that as well and signaling to have it kill itself.
That would be another way to stop the process.
So state of stopped now.
This is when it has stopped for some reason whether it's the signal from the user or in some cases when
a debugger is attached to it.
You're looking at the process and seeing what it's doing or maybe trying to figure out a problem.
It can sometimes show stopped instead of technically running because it's still in memory everything's
there.
That's just more of a halted state but this is still considered stopped from the OS point of view.
Now the state of zombie are orphans.
This means the process is not quite in the stopped state.
It's in a dead state.
That's a little misspelled.
I'll fix that.
It's it's it's in a completely dead state now when you see this you'll see it normally labeled with
a Z which when we show listings of processes.
Now this happens because the process is not listed in the process entry table in the kernel.
So the process entry table keeps track of all of the processes and their ideas so that way the main
process knows the parent problem.
Very very parent process to end it or system knows what the process is what the current state of it
is so it can be presented at any given time and you don't want these to be boxed up too much.
Otherwise you can start running into some problems.
So now we're going to take a look at working with some of these processes and some like how to identify
API and how to kill off a process of culture.
So let's go ahead and move over to the Ubuntu device.
Now let's take a look at stuff Firefox open from a previous video so we'll go ahead and play out Firefox.
So if we want to get the process idea there's a few ways to do it.
You can do something like piece of and then give it the name.
So we see that there are five PD associated with this.
This is fine.
Normally Firefox will spawn child processes from itself.
Let's take a look at another way.
So there's something called P S which is a listing of processes so if we do that real quick we see what
we have access to.
But if we do a u x we can see a list of every process being ran.
And what what it's running so we can see here that we have a process with PD 6 0 6 running to ever appear
too much too much there.
So we can see here.
No one is in it.
So in our case we're looking at it as our mom process so we see quite a bit of information here.
But we also see Firefox.
Right.
So if we look at this we can make some assumptions here.
Let's see here Firefox we'll make this little prayer right.
Let's grab this.
Ignore the case and look at Firefox.
Perfect.
Now we can see here that this is Firefox Firefox Firefox and this is our grep statement so we'll ignore
this one so we can see twenty nine seventy five is the process idea for Firefox new window and then
we've got a few spawned after it.
Now we can tell immediately based on this that this is the parent process because it's the lowest process
I.D. number.
So a child process should never have a process i.e. no lower than the parent.
Because it goes in sequential order.
So if we wanted to kill off Firefox we would kill it off with twenty nine seventy five which we're gonna
go over now.
However just before that I want to kind of give you an idea of how to view resources outside of just
peace.
So if we do something on top it's going to provide us with quite a bit of information around how the
CPA is doing how much memory is being used by a certain process.
The idea of that process.
I'm not going to go into too much on the sorting of different things.
I want you to do that as sort of some homework kind of play around with top and figure out how to sort
by the highest memory usage to hire a CPA you usage time maybe just by process I.D..
Go ahead and play around with top just to kind of get used to it.
So to get out of this relational type Q Nothing special around it.
Now what we're talking about is the this signals to kill off a process or do something of the process
you can use kill dash out.
Now this provides you with a bunch of signals.
Feel free to look these up on your own.
However what I'm going to be looking at is signal number nine which is Sig kill.
This is the standard like go ahead stop right now type process.
So what we're going to do is we want to do.
It's normally done by kill the signature the signal number which is 9 and then PD.
So in this case we wanted to do a piece of Firefox and we can see twenty nine seventy five is there.
So we'll go ahead and make this a little smaller so we can kind of see the process die
so we do kill 9 2 7 5.
It should die
so there's a few ways to kill off a process as well.
You can do p kill and then the name so we'll go ahead and spawn this back up real quick
so p kill Firefox that would go ahead and kill it as well.
And that does it by name and then we will do another one called Kill all Firefox that'll kill every
both of these kill all the processes of Firefox.
So that's kind of how processes work how to view them how to manipulate them.
Now there are a few other things such as nice levels which will I want you guys to look at for homework.
But look a little bit further into how processes work.
I'll link a few links above the video for extra reading so feel free to read into those again if you
have any questions.
Jump over the Facebook group and pose any questions.