[No audio]
Processes and jobs. Before we get into
this lesson, I want you to understand
what exactly each term means in Linux
environment. Well, first we have
applications, which are also referred to
as service. An application or a service
is like a program that runs in your
computer. And then application could be
anything like in Windows, you have
Microsoft Word, PowerPoint, and Linux,
you have programs or applications like
NTP, NFS, Apache, and whole bunch of
different programs. So that is an
application and service that runs on
your computer. Then you have a script.
What exactly a script is? A script is
something that is written in a file, and
then packaged it to in a way that it
will execute. So any application that is
running in your computer, for example,
Apache, you would have to run that as a
script. And that will run in the
background. So that's actually a script.
And also all those different commands
that we run in our Linux environment,
all of them are also referred to as
scripts. Then we have a process. What is
a process? When you run an application,
or when you store up an application, it
actually generates process, with it's
process ID. Now processes could be one
associated to that application, or it
could be multiple processes. Then we
have daemon. The daemon is, I could tell
you when I compare it with a process, is
something that continuously runs in the
background, or it doesn't stops. So when
you run a daemon, which is also a
process, but it keeps on running in the
background, and it keeps listening to
the incoming traffic or outgoing
traffic. Then there is a thread or
threads. Every process could have
multiple threads associated with it. An
application that is running in your
background, let's say NFS. When you run
that application in your Linux machine,
it could have many multiple threads. If
a machine or remote machine tried to
connect to you through NFS, it will
generate one thread for it, and it will
generate a second thread or third thread
for other computers that are attaching
to it. Then we have a job. A job is
something that is created by scheduler,
like a work order to run those
applications and services. In process
and service commands, we have a first
command is systemctl. This command is
now used in Redhat 7 and it is
being replaced. Sorry, if the old
command that was running an earlier
version of Red Hat or CentOS service.
service is now being replaced with a
newer command systemctl. Then we have a
ps command. This command allows you to
see what are the processes running in
your Linux system. You could use
different options with that, to find out
exactly the process that you are looking
for. Then you have a top command. Now
when you run the top command, you will
see all your processes running in your
system, depending on which process you
want to see first, based on its load,
and it also tells you some your memory
information CPU information that is
being used by that process. Then we have
a kill command. The kill Command kills
the process, it kills by the process
name or kills by the process ID.
So when you start an application, again
going back to our example of Apache,
when you run an application HTTP, which
associated with Apache, it has a process
ID to it. You could stop that process by
running systemctl stop httpd, or you
could simply kill followed by the
process name or process ID. We'll cover
kill command later in this lesson. Then
we have crontab. crontab command is used
to schedule these applications or
these process or these services for you
in your system. You will run crontab
with minus e to edit it, and there are
different options that we'll cover with
the crontab. So when that crontab when
that process or application is scheduled
in crontab, that becomes a job. And the
last command that we'll cover is at. at
command is just like crontab. The only
difference between at and crontab is, at
is scheduled as a one time basis or as an ad hoc process.
[No audio]
We'll look into our Linux
machine, and we'll go over the processes
and some of those commands. Let's log
in, clear our screen, cd, check where we
are, who we are, and what is the hostname.
Good. So do clear. All these commands
that we will be running, most of these
commands need root privileges. So we
could either become root on this
terminal or we could use a PuTTY terminal,
whichever the terminal that you prefer.
For this, we will stay on the console so become root.
[No audio]
Okay, let's clear this out. Now systemctl
is the command to start an
application or stop an application. It
also is the command that is used to list
or sorry to enable an application to
start or stop at the boot time, meaning
every time your computer starts up,
you need certain applications to run. So
to start an application, let's say I
wanted to start an application called
NTP. NTP, is a daemon that runs all the
time, which stands for Network Time
Protocol, which syncs your time to other clocks.
[No audio]
So systemctl restart ntpd.
The d we are putting in because it's
telling it it's a daemon. You hit enter,
and you get your prompt back. The reason
you get your prompt back is because it
did start it that NTP service. Now how
do we check if that service is running?
You do ps and the option that I use my
favorite is to have I open or dash ef,
you could use other options. ps minus ef
you hit enter. When you hit Enter,
you're going to see all bunch of
processes that are running in your
system. Do you really want to look into
all these processes? No, you are looking
for only one process which you just
started. So you do ps minus ef, pipe it,
grep it, ntpd, and it will tell you
yes, the process is running or the
application is running. That's right
here. You could also use the same
command systemctl status command to
view if the process is running. There it
tells you right here, the Network Time
Protocol, that's a service. And it's
loaded and it's active and it's running.
And it's running since the time and it
gives you a lot of other details.
Now what if you want it to stop this
process, you could do systemctl stop
ntpd, and it stopped. See if it still
exist, ps minus ef grep ntpd, it does
not exist. If it does not exist, then why
we are getting this line. Well, if you
pay very close attention, this is
telling you that the command that you
just ran ps minus ef, when you run
this, the Linux system, the operating
system is so fast and so sure, that it
gets you the same command that you
running. You see it's giving you this
grep, that I ran this grep, and if and
this grep is also considered as a
process itself, within itself. So that's
why it's giving you. You always going to
get this grep whenever you run this
grep command. So this is about ps systemctl command,
and if you wanted to enable
an application, you could just run
systemctl enable ntpd, and this will
enable. See it says create a symbolic link
is create a symbolic link in the etc
configuration file. So now every time my
computer, my Linux machine is going to
start, it will start the NTP daemon with
it Another example of different process
is sendmail or rsyslog. Let's see
rsyslog is another application or
process that runs which collects your
logs. So let's see if it's running. Yes,
you see it is running. And if you're
wanting to check the status, you could
also do systemctl status rsyslog.
[No audio]
And it will tell you it is active and it
is running. So that's how you find out
about all the processes. Now, what if
you want to kill that process?
So let's take one step back, and we'll
run top command. top command is one of
the favorite command for many system
administrators, because this will tell
you about the system resources, or also
one of the favorite question by an
interviewer, who was going to interview
you, they will ask you tell me about how
do you monitor the system? This is where
you could tell them you will run the top
command, and the top command will give
you their total number of total tasks, 171
is running, 169 is sleeping. What are the
CPU, usage, is it too high, is it too
low, what is the memory usage, what is
the swap space, and then right here it
is listing every process that is running
in our Linux environment, with the
process ID, who the user is? And what is
the memory being used? What is the CPU
being used? How long is it running for?
and what is the command associated with that process? So this
has so much information that I cannot
cover in this lecture. So what I will
encourage you to do is, do man on it or
read a lot more about it in different
documentation, I will also include some
documentation that will explain top
command in detail. You could also feel
free to Google it, you could view top,
but you should spend some time quite a
bit time to look into the output of this
command. Now what if you want to get out
of it, just simply type mpt Once you type
Q, you will get your prompt back. Now
we'll go to the command kill. If you
remember, we use ps minus ef to check
which processes are running, grep, and I
wanted to do ntpd. So NTP is not
running. Let's start it first. So we'll
do systemctl restart or start, doesn't
matter, ntpd. It has started, let's check
again, ps minus ef grep ntpd. It is
running. Now I wanted to kill this
process. There are two ways to do it.
One is if you do systemctl and do stop,
this command or you could simply do
kill. kill will kill the process,
regardless of whether it's going to go
down gracefully or not. So which process
we're going to kill right here. This is the process ID.
[No audio]
So kill simply 12027, the
process ID, hit enter. Now let's verify
if it killed it.
Yes, see, it's gone.
Because we are killing the process ID.
The same way whichever process that you
have, you could just do kill, ps minus
ef, and then do more, because you want to
see all the processes. There are tons of
processes that are running through your system.
Any process that is hung you could
kill it. And how do you know it is hung,
you could type top command and you will
see here under memory or CPU if any of
the process is using, let's say 99% of
CPU or 99% of memory, that's definitely
one of the your candidates to use the
kill command to kill it to free up the
resources. System administrators use
this command many times to keep your
system up and running and healthy. Next
we will learn crontab. Let's exit out, and
we will become ourselves. crontab allows
you to schedule our scripts or our
commands whichever way you want to
schedule. So let's say I wanted to
schedule to create a file that has some
kind of output at a certain time. First,
let's check the date. My date is
Tuesday, March 13 2019. This clock is
one hour off, I want to set this clock
first, so become root, set this clock.
[Author typing]
And I'll do date minus s to set. And it will
be, I think I have it set here. Yes, it
will be 13, march
[No audio]
2018. Did the hour,
[No audio]
the hour,
[No audio]
time, the second,
hit enter. And then you do date and it
sets the correct date. Now let's go back
to our self whoami, and we are self,
clear the screen, now let's do crontab.
[Author typing]
crontab is a command self, you have to do
crontab minus e to edit the content, and
specify whatever that you are trying to
schedule. Hit enter, the first, once you run
sorry, once you run crontab minus e,
it will bring you to the vi editor mode,
the same way as if you run vi followed
by the file name. So you are in there,
hit i to insert. The first one is the
minute. So we want to schedule something
at 22, second one hour, 13, then
the day of the month, I'll put every day
which is *, month is three which is
March day of the week. I'll do every
day. Okay, so we scheduled a time. Now
what do we want to do? We wanted to do
echo, This is my first cron tab entry.
And I wanted to put that to a file. crontab-file,
or crontab-entry. So if
you notice the file time has quickly
changed, it already become 122. So I'm
just going to change 23. Hit escape, write,
quit, and hit enter. Now the time is 21.
They still have 43. So let me just do
quickly,2, so this will be don't lose time.
date, 53. Let's see. Do we have the
file created yet? Yeah, this is the
first one I had it before. That's fine.
date 22. Perfect. So let's see, did you
create it? There you go myfirstfile.
[No audio]
Sorry, not myfirstfile, ls -ltr,
it will be a crontab-entry, because we
are doing crontab -l, it created
crontab-entry. And the crontab-entry is
cat crontab-entry. This is my
first crontab. So it did create it. So
but it created itself. So I schedule it,
that's why I created it. To do a quick
comparison of our commands that we
learned with our Windows environment is
the first one systemctl. When you are in
your in your Windows environment, right
click on your Start Task Manager. You
see all these applications, these are
the application you can stop and start
using the systemctl in Linux. These are
the processes that run, that are
associated with all those processes. And
many of them are daemon processes like
service host host process for Windows.
Many of these run as the process. These
are the services that you could shut
down with systemctl and the performance,
remember we ran the top command. The top
command tells you about your CPU, your
memory. Exactly this is what you're
looking at with the Windows Task
Manager. This one gives you the network
usage and of course the User itself. So
this is a quick comparison between
Windows and Linux. And I hope you will
run all these commands one by one to
learn more about them.
[No audio]