Latest Posts
Monday, April 11, 2022
In this post we are going to look at another performance related command, which is the uptime command.
First let's look at the uptime command, as the name implies the uptime command shows you what the uptime is for the system:
The command shows you the uptime for the system, the number of users who are using the system, and the system load average (Number of CPU used) in intervals of 5 minutes.
If you type w, you can see which users are using the system
The load average is the most important stat in the uptime command however, it is currently static, and to get updates you need to run the uptime every 5 minutes. There's a better way to monitor your Linux system. But you have to call now, and for a limited time only for just $19.99 you can have the answer. Since I am such a nice guy I am going to give you the answer for free.
What you can do is type the command tload and it will monitor the load average time in real-time. Before we run the tload command a good command to run is the lscpu command to see how many CPU you have. For instance you have just one CPU and your load average is 1+ then you have got a problem.
Now let's run the tload command
There are two parts to the tload utility, at the top you will see the average load time in real time instead of the 1, 5, 15 minute interval like before. But it will be dynamic and updates automatically based on the load.
On the bottom you will see a graphical representation of the load average, it's probably not going to win any awards for best graphics
Everything looks fine right now, but if you open another terminal and run the dnf update -y command you will see the load changing accordingly. Or some tasks that would put stress on the system.
Monday, April 4, 2022
In this post we are going to look at the procps-ng package commands to get some performance related information on our Linux system.
The first command we are going to look at is the free command, which shows the free memory available
We can use the free command with the -m option to show the free memory in megabytes
Or free -g for gigabytes
The next command we are going to look at is the pmap command, let's grab a process id for this one with the ps -l command
Let's run the pmap command on the bash process, the pmap command displays the memory map of a process, besides the memory usage it's nice to see the shared libraries used for the process
Another useful command is the pwdx command, this command finds the home working directory of a process. So if we run the command pwdx 3368 we will find out what the home working directory of the bash shell is
Monday, March 28, 2022
In Linux you can control the priority of a process with the commands nice and renice. There are limitations if you are a non-root user. The nice and renice commands have the values in the range of -20 to +19. The higher the numbers the higher the priority, or the nicer the process is meaning the less CPU it would use, so it's kind of the opposite of what you are thinking. So it's like nice guys finished last?
So if we run the sleep process again let's see what happens by default
sleep 1500&
As you can see the priority(PRI) is set to 80 percent by default
Now let's be a nice guy and assign the sleep process to the nicest value -19
As you can see the new sleep process is set to priority 99 meaning only run the process if processes with the a lower number is ran first. It's like being the 99th person in line.
If you run it at the highest nice value, not so nice. Let's see what happens
You can also reassign the priority of an existing process with renice command, with the renice command you have to specify the process id
Linux was nice enough to tell you that the process has been changed from priority of 19 to 5, so now the process is assigned a priority value of 85. Still the nicest priority!
The caveat on the renice command is that if you are not a user with root privileges, you cannot set a higher priority than the original priority of a process.
If you are root you can also control other user's priority settings by editing the /etc/security/limits.conf. Priority is the last item or settings that you can set limits on, so move to the end of the line and type in the following for user limit, if you want group limits you just prefix it with the @ sign
Now the next time techjunkie sets a priority he will be limited to priority number 5 nice value. Since he is not a root user he cannot renice the process to be anything higher than 5. Therefore he is a pretty nice guy.
Monday, March 21, 2022
Linux allows you to run jobs in the background and in the foreground. It accomplish this by identifying the processes as jobs and assigning the state to the jobs by numbers.
First let's create a process, we are just create a sleep job in the background, with the command sleep 1500& the & automatically put the process in the background. If you observe the behavior you will noticed that the prompt is in your control right away because it's running in the background.
If you run the jobs command you see the process is running but it's running in the background. However if you forgot to put the & at the end the job will have to be finished before you get your prompt back, the only way to get your prompt back before then is to type CTRL+Z , but that would also stop the process or job from running. That's probably not what you wanted
You've gotten your prompt back but you've also stopped the process, that's probably not what you wanted to do. You want to get your prompt and keep the job running at the same time. So the solution is to use the bg command to run the job in the background
To bring the job into the foreground you just type fg
As you can see you lose the prompt once the job is put in the foreground because it has to finish running the job before you can get the prompt back. Press CTRL+Z again to interrupt the process
Now there's another way to put a process in the background, that is to specify the job number. So if we want to put the second job that was stopped in the background again we can type bg 2
You can do the same thing with the fg command. Kill the sleep process with the command pkill sleep for cleanup
Monday, March 14, 2022
Since searching for a process and killing process is such a common task there's are shortcut commands available for these tasks in form of pgrep and pkill. As you suspect these commands are used for finding and killing processes respectively.
For example we can search for gnome processes like this instead of combining the ps command with the grep command
Or to get more information you can use the command like command below to get the full listing
[jhuynh@cent7 ~]$ ps -F -p $(pgrep gnome)
The pkill command works in similar fashion, so instead of killing the process by the number, you can just kill the bash process with this command pkill PID, one caveat is that it does not work like kill -9 so your usage may be limited.
Another useful command is the top command, this command will sort the processes that uses the most resources first by default. All you have to do is type top in the terminal
You sort it by other attributes as well such as memory, by default it's by CUP usage, to get to the other options type the f key
Select %MEM and type s to select it and press esc to sort the top screen by memory usage
Monday, March 7, 2022
The kill command in Linux is a powerful command to kill a process. You usually see the kill command accompanied by the process ID however there's other ways you can use the kill command. To get a list of how you can use the kill command, type kill -l
There's one important thing that you have to remember as a standard user you can only kill are your own processes, so if you have two terminals open and one of them is not yours. You can only kill the processes in your terminal or session.
Let's say you run the command ps to see the processes that are running, all you need to kill a process is type kill -9 PID
So it's something like this kill -9 3544 to kill the bash process this will kill the terminal, alternatively you can type out the word that corresponds to -9 with the command kill -sigkill 3544
Monday, February 28, 2022
In Linux managing processes is an essential part of keeping your system running in an efficient state. In this post we are going to look at the commonly used ps command.
If you just type ps you will get the processes that's currently running along with the PID (process ID), TTY (terminal it is running in), Time (CPU utilization time), and the command that is used to run the process
Here are some of the options that are useful with the ps command:
1. ps -e this will show you all the processes
2. ps aux this will show you all the processes that are not assigned to a user terminal
3. ps -e --forest this will show you the process tree view of the process
There's a nicer way to look at the process tree with the command pstree
4. ps -f gives you the full ps process information which includes the user id and the parent process id
ps -F gives you even more information about the process, it gives you the size and RSS (memory size) of the process
5. ps -l shows you the long listing, which shows you different kinds of information like the UID (number) and the process priority
6. You can combine options with commands like ps -elf which will give you the full ad long listing
7. As with other commands, you can search for a process when you combine it with the grep command. Let's say we want to search for all the gnome processes we can type the following ps -elf | grep gnome
8. ps -ly will replace the address column with the resident size (memory size)
Monday, February 21, 2022
GRUB2 is a wonderful tool, and one of the cool thing you can do is create a custom entry on the boot menu. Let's say you built a system especially for HR and it's different than the rest of the organization's system. Well with GRUB2 you can create an entry for the HR system as one of the choices in the boot menu.
Here are the steps to create a custom entry in GRUB2:
1. The first thing we want to do is create a custom file in our root home directory with the following contents. Log in as root and make sure you are at the root home directory and type vi custom your linux16 entry might be different so make sure you have the right path in production. In this post we are more concerned about making it show up in the boot menu
2. To make it show up in the boot menu we want to edit the 40_custom file in the /etc/grub.d/ directory. So type vi /etc/grub.d/40_custom in the terminal. Now you want to go to the end of the file and append the custom file to the end of it. The way you can do that in vi is type esc then type :r /root/custom and press ENTER
The completed file should look something like this
Type esc, :x to save the file
3. Now regenerate the grub.cfg file with the following command grub2-mkconfig -o /boot/grub2/grub.cfg
Monday, February 14, 2022
From the past few posts you can see that GRUB2 is a very powerful utility in Linux. It's so powerful that you can create and change the root password. One way to prevent unauthorized access to this feature is to password protect it and encrypt the password as well.
Here are the steps to password protect GRUB2:
1. Make a copy of the file /etc/grub.d/01_users with the command cp /etc/grub.d/01_users . in the terminal
2. Go into the grub.d directory with the command cd /etc/grub.d
3. Now you want to edit the 01_users file with the command vi 01_users
4. The file should look something like this, by looking at the file you can see that it's currently using the root encrypted root password for authentication. What we want to do is use a user that's not in the system to control access to GRUB2.
Here is what the file will look like with the new user
Save the file with esc then :x enter
5. The next step is we have to regenerate our configuration file with this command grub2-mkconfig -o /boot/grub2/grub.cfg
If you get this error message
/etc/default/grub: line 7: unexpected EOF while looking for matching `"'
6. Now if you press e at the GRUB menu you will be prompted a username and password, you can authenticate by typing in the username and password you just specified
After typing in the username you will have access to functions for system administrations, just type Ctrl+x to go through the normal boot process
7. That's great and all but the password is stored in clear text and a someone can just look at the file to figure out what the password is. To encrypt the password type in the command grub2-mkpasswd-pbkdf2 to get the encrypted password. Copy the encrypted password into the clipboard
8. Go into the grub.d folder with the command cd /etc/grub.d/ and edit the 01_users command again to change the password to an encrypted password, the file should look like this
Obviously your encryption string will be different depending on your password, save the file by typing esc, :x.
9. Regenerate the grub.cfg file with the command grub2-mkconfig -o /boot/grub2/grub.cfg
10. Now when you are confronted with the password prompt at the GRUB menu you can type in the password as you were before but now it's encrypted
Monday, February 7, 2022
Having to change our grub menus with a text editor every time we want to make a change and be cumbersome and error prone. Luckily there's a tool that we can use to work with grub called grubby. In this post we are going to go over some of the useful commands that comes with grubby.
The first command we are going to look at is the grubby --default-kernel as you may have guess this will display the current default kernel
In addition to showing the default kernel we could set the default kernel with the command --set-default kernel command, with this command though you need to know the exact path to the kernel. Let's set the default kernel to be the second choice. To do that we want to see all the choices first, to list all the kernels we type the command grubby --info=ALL
From the command we see that the second choice is kernel=/boot/vmlinuz-3.10.0-1160.el7.x86_64
Now we can set the default kernel to be the second choice by typing gubby --set-default /boot/vmlinuz-3.10.0-1160.el7.x86_64


































