Okay, Welcome to 13.5.
Creating Monterey and killing processes.
It's kind of funny. Welcome to one of three down five. Sounds like I'm talking about a radio station.
linked to everything that's happening within your operating system, so we need to be able to
find the appropriate process based on its I d. Number who owns it? Which group? It belongs to some portion of the name
and be able to manipulate the process to serve our needs as administrators. Shutting things down, grace believe versus killing them,
changing the priority of processes. These are all important considerations.
So you have a big list of commands here.
We'll learn how to put processes into the background and bring him back to the foreground. Kill them.
Look at various listing methods
so that you can see the information that you're you're
interested in in a more efficient way.
So when we run a job in the foreground, we have to wait for that job to complete before the prompt returns to the shelves.
Sometimes that's not a problem, but certain things that may take a long time. We might want to put into the background so that we're not waiting for that to complete.
If you only had a single terminal connection, you have to do a lot of background work, because otherwise you'd be waiting all the time for things to finish.
So it's a great way to be more productive because you can
run a bunch of Koreans, keep putting them in the background, check on their status, and as they complete, you
So we put a process in the background by adding an ampersand after the process or after the command name on the command prompt.
Once that happens that a job gets created
and the jobs will be begin a job number one and we'll increment as required.
We can just look at those jobs by running the job's command,
listing them, listing their their process I d numbers and then put them in the foreground and background
and we'll see how this works.
So what? I hope so. Sorry about that.
A convenient way to demonstrate this is to run the sleep command
because I can just tell it to sleep for 5000 seconds.
This gives me time to, um,
I shall do it differently.
We'll do a sleep command for 100 seconds,
asleep for 500 seconds.
You'll notice I forgot to put him presents behind a couple of these.
That means the 1st 2 would have gone to the background, but the 2nd 2 would not.
sure it did. There is fine.
All right, so I've got several jobs created. We can see the numbers here. Job 123 and four with the associate ID process ideas.
I could run the job's command by itself,
and it shows me that data
a plus sign here means that's the most recently run job, and the minus sign is the one right before that.
So it's a nice little extra bit of information that I can use
now if I run jobs. Dash L.
This shows me the process I d. Number with the
So it's a long listing form,
or I can run jobs Dash P
to just look at the process I d. S.
Either way, it's pretty useful.
what I can do is take one of these jobs that's currently the background. I could bring it to the foreground that might increase its processing priority.
There's there's reasons for doing that.
So what I can do is run the f G command for foreground
and I'm gonna run it for job number four.
So sleep 2000 was that job. Now, of course, it's in the foreground. So I have to wait until
this job completes. In order to, uh, get my prompt back,
I could open another shell, but these jobs are specific to this instance of the shell, so I won't see those jobs in another show. We contest that
and I run the drops Command. I don't see anything because I haven't created any jobs here.
Create job. I've got it. But now I can't see that job number one is specific to This show doesn't belong to the other show.
I'm gonna go ahead and exit out of that
here. If I want to get my prom back, I could do a control. See,
that particular job is now no longer running.
Job number one was sleep 100.
it says that one's done
because I basically I exited by by using interrupt control. See,
Haven't you jobs are still going?
also take a job that's currently in the foreground and push it to the background,
and that's pretty useful
All right, so now that I've got my sleep jobs in the background, all running,
I might decide that I need to interact with one of these jobs,
but a backup script. Who knows what these things might be in a production situation here. We're just illustrating it with the sleep command.
What I can do. Since I know the job numbers,
I can take more of the jobs and bring it into the foreground by using the F G command.
So job number one, I'm gonna make that a foreground job.
Now you'll notice my command show is no longer available to me. I can't. I can't interact with it
as it is because the jobs in the foreground, as if I never ran it in the background to begin with.
What I can do is hit control Z
prints to the screen
and it stops the job.
Now, if I run my job status,
I can see that job number one is has now stopped.
Now, once I Once I've done this, I can, uh,
decide that I want to put this job into the background again. Maybe I'm done with whatever interaction I needed.
So I can just run the BG command
and it's back into the background.
Now, if I bring a job,
into the foreground or bring in the background, there might be different reasons for doing that. Could be that you want to change the priority. You want to do something else,
and it might be your only option if you have that single connection.
Another useful feature of the shell is the no hang up from Jin Ality.
So no help allows me to run a job in the background.
And then I can log off the system without that job exiting, which would, which is what normally would happen
in this example. Maybe I'm running a backup script and it's gonna take 56 hours. It's about time to go to lunch. I don't want to wait around, so I'm gonna run this script.
If I don't specify any output,
it goes to know hopped out out.
Although I could specify one here
to redirect output. Thio Some file of my choosing like a log file
to the second file descriptor is standard error. If you recall we talked about that a little bit earlier.
Maybe I want to send my errors to a separate file as well, so I can
go back later and just review that information that I'm most interested in. And then, of course, running it with the ampersand for the background.
So let's see how this works.
I'm going to start a new sleep process 3000 since that's a number that I can find easily later.
and just send it to the background
if I wanted to, I could redirect standard out
to my current directory
There's really no purpose for sleep. It's not gonna really give me much is gonna tell me that it's running,
and I could redirect the standard error with
You could do it like this.
It's gonna do you always to pick, uh,
extensions to make sure you know what? What? What a file is not. Text is pretty
anyway, So sleep 3000
tells me it's now a pending my output to know helped out which I can look at later Have a hit enter. I get my show back.
So now I can actually exit from my shell.
You see that? It gave me a process i d number when I ran the job.
So I can just verify
that my sleep process is still there.
I could have done this in different ways to, um
but we'll look at the process, commands a little bit later.
You see that this proves my job is still there. Now if I go back into my show,
actually, this will be a new shell, so I shouldn't be able to see that job.
I can still see the process,
but if I run jobs, there's no jobs in this queue because this shell is separate from the one that I started that job.
The process is still running it. It's just that that job is no longer
attached to the shell, that it was launched from
hope that makes sense.
Anyway, let's let's talk about monitoring process easy. So me just use the P s command a little bit there
and there are several options for P s that are really useful. We'll talk about those in just a minute here.
you need to be aware of the top utility.
This is a even though it's on Lee text based. It's very useful because it gives you a real time update
of various different details about your system.
What my load averages memory. You said CPU usage.
I can kill a process from here. I can also re nice a process
which allows me to change its
priority within the system.
So let's have a look.
So the P S command is pretty useful for viewing processes in lots of different contacts.
Let's start off by looking at it.
Now, this one, we have to specify either help simple list or output.
Um, somebody used a simple help.
Just give me some basic settings.
List. Gives me a little bit more
when we use the P s command, we're just checking the processes that we have in the current shells. I can just type yes by itself,
and I can see that I'm running a bash shell and I ran a PS, commanded it, tracked its own process.
I'm gonna look at UH,
a larger scope of process easily for the whole system.
Usually I would run PS Dash E f.
So he gives me all processes
It gives me the long format.
So it's a long format listing.
I can see the user I d
process i d. The parent process i d
current system time when it started
time that it's been running and
long format shows me a lot more details for what commands are running with options that were run with.
But, of course, is a big list toe look through and not very efficient.
options. We'll explore the PS command a little bit further in the next slide here.
let's look at the top utility.
Now. Top is very useful because it gives us a real time
different things. They're going out with their system. I can, for instance, go to the help screen
by typing question Mark.
I could turn on colors,
toggle the bold option. We'll see what that looks like.
I can look at my load average, which is my
one minute, five minutes and 15 minutes
I can look at my Cebu information, my memory information.
I can find a process by its name
and I can do some other kinds of sorting. I can look at idle time,
sort by the tasks that are currently running.
I could search by a user by using the Yuki
and I can kill and re nice processes.
There is a you for user killer. Re nice is always good Change the update Interval I think by default it's three seconds you see up here
So let's have a look at some of these options.
First we start with a Z
the color mapping that's a fight if I hit the control are sorry. Shift Z I get this screen
headings Aegis by itself turns on color.
This might be a little difficult for some people to see.
I usually don't use it, but I like the B option for bold.
I can set it for highlighting the entire
line that's currently getting some priority
or typing it again. Hitting be again. I can see some lines, are emboldened, some or not
Let's see for CPU, I can uh,
changed the sorting. So
But now I'm looking at the lowest levels and headed again, and I can see the highest levels.
And it tells me information up here, I can see my load average
parameters showing me how hard my system is working.
load average showing me,
how much memory I'm using. How much swamp I'm using.
I can hit em for memory and see a nice little graphical representation of how much remember I'm using versus my swamp.
Go back to the help screen for some more options.
The U option for finding a
process related to a user
So it tells me what user I'm interested in. I could just say show me admin.
These were all that process is running for admin
shift. L Let's me look for a string in my process list
so I could look for something like I bust. Is that because I happen to see it there
and it highlights it
I can type in K to kill a process
by default. It gives me the one that's at the top of the list when I hit the key,
and I'm just gonna type, um,
had escaped to get out of that. I don't want to kill anything,
re nyssa process with the Archy
and re nice means I'm changing the nice value, which we'll talk about here in a little bit.
And one other thing that's useful to look at
is the task summary.
So I can be for this,
and it's trying to show me based on my priority levels and virtual memory,
storage that storage, but utilization for the particular process.
All right, so so top is kind of useful. I can do a little bit of administrative tasks from here, but mostly it's for viewing things and trying to find information and a little bit more user friendly way than the PS command from the command line.
Let's quit out of there
look at some examples for PS.
I have lots of different options. I can search by the user name search by
search by the group number of the process I D number
and these are the fields that process at the process. I
process listing command shows us your I. D p. i d parent
my system time t t y and other parameters.
Let's go do a few examples there.
I was starting to say before P S e f is pretty handy.
Maybe I want to do a quick and dirty search talking. Just say, Oh, show me everything that's related to bash
So just taking the output of PS, piping it to the grab command and looking for Bash.
This might not be very specific, though, so maybe I'm say, Well, show me
that also has to do with Bash.
And there's my one bash l
If I don't use any other filter, I just see all the admin processes
Sorry, that habit. I can search by
So user admin is the owner and admit can also be a group.
Maybe I want to search by a particular process I d. So I can use the dash p option
and let's see one here 2 to 19
So it shows me what that particular
but in the easier. Since I tend to prefer grab because
I can just run a full process cf listing and do searches for things that I'm interested up. And
there's also a couple of related commands a p i d of and P Group.
Can I see that I've gotta sleep process running here?
Actually, I've got more than one. I'll do a P I d of
No, no, nothing there. I'll try bashes. I know I have a bash l
So there's my three process I. D. S related to that string bash that I just searched for.
If I run a p grip for bash, I can do something very similar. I get a slightly different output,
in both cases, I'm able to search for process is based on their name.
So once again, you have multiple ways to
accomplish the same goal finding processes by their number, finding him by their parent process. I d fighting it by a port number of part of a command. You've got a lot of different opportunities for surgeons
when we are dealing with processes or managing. Then we have to be able to also send them signals.
When I was demonstrating the foreground of background commands. Earlier
you might remember I used control Z to stop a process.
I could also reference a process by its job number by using the percent sign here.
So if I knew a process I d number is our day job, i d number. I could kill it with this command
or I kill it with the process i d. Number
are available. I have signal hang up, which is a kind of a graceful way to
to end a process, said Kill is much more forceful, so some processes may not die easily,
so we might have to send the kill command.
There's a termination request
also a friendly way to shut down a process
and said Stop which will stop a process very similar to what control Z does.
We send signals using this notation here
so I can send some processes, some signals. Let's start up another sleep command
sleep 600 I'll sleep seven hundreds. I could tell them apart
jobs and I can see on the jobs de shell so I can see my process. I d numbers
Now I could send a kill signal based on the job number.
So if I specify killed job number one,
look at jobs. It shows me that that's terminated.
I actually don't need that more right anymore. Um,
so now I only have the one job right
now, I can kill this one using its process I d number
In a process i. D. Number of 39588
jobs. That one is now terminated.
I'll start up a new one.
There's my job that's running
in this case. I want to do kill Dash nine.
Sometimes again, jobs are
difficult to just to stop because of the way that they're cooked into the system. And you may need to use the more forceful kill method.
Killed nine is kind of like the big Hammer.
So now that job is dead,
and I'll start up another sleep job.
In this case, I'm going to send a stop command to the to the job,
So kill dash cigs Stop.
Helps if you specify the process, i d. Number 39672
I can see that job has stopped.
This is just like hitting control Z. So when I could also do
is put that job into the background,
referencing it by its job number. So check the BG command with job number one.
Can we type jobs again? It's running and it's in the background.
Sick terminate so I can type sig term.
This terminates the process,
and I want to also specify the P i. D. Number.
But I can also do that with the job number. So I knew that it was job number one,
so I could do that here instead of finding the p i d. And typing that in.
Okay, so we looked at a lot of different commands in this section.
He learned how to start. Stop process is putting them into the foreground, putting him into the background,
setting a system up or sending a process up so that it can run after we've logged out.
We also looked at the top command
and some of the ways that it can be used to view processes
and be able thio to change their settings.
All right, that gets us to the end of the section. Next we'll talk about modifying the process. Execution priorities.
Here we'll learn more about how to bud
use the nice commanding the re nice commands to
change. The priority of important process is running on our system.
All right, see, in the next section. Thank you.