Linux Essentials        2

Links        2

Linux distribution        2

Example of Linux Disto        3

Linux embedded system        3

Linux in the Cloud        3

Linux Commands        4

Directories        4

Basic Commands - 1        4

Process Commands - 2        4

Log Command - 3        5

Tar Commands - 4        7

Searching data Commands - 5        8

Hardware Command - 6        10

Network Commands - 7        11

User/Permission Command - 8        12

Applications        13

Desktop application        13

Server applications        13

Chronology of source code to executable file        14

Package management tool        15

CLI        15

How it works        15

CLI Syntax        15

How it works        15

Variables        15

Quoting        16

Man & Info command for Help        17

Linux directories and file system        17

Linux OS        18

Internet, Network and Routers        19

User and Groups        21

Linux - LFCS        23

Essential Command        23

Find/Locate        23

which/whereis/type        23

File Systems        24

Manipulate File Content        25

Redirection operators        26

Regular Expression - Regex        26

Archive/Backup/Compress/Decompress        27

Hard/Soft Links        28

File Permissions        30

Manage access to the root account        31

Tasks        31

1. Backup App via archive by Tar        31

2. Add/Change execute permission to files and view/change attribute        32

3. Finding Files, and Assigning Permissions and Ownership        32

4. Transfer Files Securely Over the Network        33

Operation of Running Systems        33

Boot, Reboot, and Shut Down a System Safely        33

Linux Server Troubleshooting Guide        34

Methods        34

Commands        34

Scenarios        35

Kernel Buffer Commands        35

Virtual Memory Commands        35

PID Status Commands        36

Linux Essentials

Links

LE: https://lucid.app/lucidchart/fc06cd7d-70f2-494a-843b-5d86ffb4331e/view?page=8L66hCFYoXKS#

LFCS: https://lucid.app/lucidchart/e5ec169f-ec73-4171-85e6-79fefdfea848/view?page=0_0# 

Linux distribution

Example of Linux Disto

Linux embedded system

It’s a combination of hardware and software for a purpose

Example: android and raspberry pi

Linux in the Cloud

How to SSH/Connect to a remote server

Port used: 22/TCP

Linux Commands

Directories

https://opensource.com/life/16/10/introduction-linux-filesystems

  1. /etc = stores system configuration
  2. /boot = linux kernel configs and files
  3. /sys = where the data is stored;
  1. /proc = sudo file system where kernel gives info about processes
  2. /dev = device
  3. /tmp = directory that holds large less important files. Files will be deleted upon booting the system
  4. var/temp = hold more persistence file. Files will be deleted after 30 days.

Basic Commands - 1

Command

What it does

whoami

Return user name

uname -a OR -r

Which Kernel is this

cat /etc/*release*

Show which distro you are on

pwd

Print working directory

cd ~

Change to home directory

cd /

Changes to root directory of file system

ls

List of files

Ls -a // prints hidden files(starts with .)

W > log.txt

Redirect the output into text file

Last >> log.txt

Append output to the same text file

grep -i usb

Prints usb from the file // -i = casing doesn’t matter

Process Commands - 2

Process and PID: In Linux, when an executable stored on disk is called a program, and a program loaded into memory and running is called a process. A process is given a unique number called process ID (PID) that identifies that process to the system, when it is started

w

Anyone logged in

last

Shows last person to login and last time system rebooted

uptime

cat /proc/loadavg

Shows howmuch time the server is up

  • What is the current system load

cat /etc/passwd | wc -l

This file has all the users on a linux

sudo dmesg

sends info about kernel (hardware related info)

htop

Shows running processes on a host

  • Gives processes that using the most CPU
  • Useful for troubleshooting load issues

ps aux

ps aux | grep Gautam | wc -l

ps -eF | grep Gautam | wc -l

ps -U User_Name | wc -l

Dump out all of the processes

To grab howmany your process is running

the Same result as above

Howmany process running as given user name

ps aux | grep process_name

Grab process ID(PID) of given process name

cat /proc/PID/status | grep threads

Grab howmany threads is the process running

service S_NAME status

Which linux service is running

Log Command - 3

/var/log

Examples:

sudo cat /var/log/httpd/access_log | grep -E “^10.0.1.10”

All general logs saved here

Howmany time has 10.0.1.10 has access the site

last

Shows last person to login and last time system rebooted

Tar Commands - 4

tar cf archive.tar test_file_*

Archive test_file_* into archive.tar

tar tf archive.tar

Look through/List files in the archive.tar

tar rf archive.tar file?

Append/add additional files into archive.tar

tar xf archive.tar file3

tar xf archive.tar // extract everything

Extract specific file from the archive.tar

tar xf archive.tar –wildcard ‘test_file_?’

Extract list of files using globbing(?,*) via wildcard

tar --delete --file=archive.tar file3

Remove file from archive.tar // edge case

tar czf archive.tar.gz file_*

Compress(to reduce file size) file via tag czf // gzip algorithm

Why?: if you’re running on low disk space 

tar cjf archive.tar.bz2 file_*

Compress(to reduce file size) file via tag cjf // bzip2 algorithm

zip -r archive.zip file_*

Compress(to reduce file size) file via option -r // zip algorithm

Searching data Commands - 5

cat gautam.txt | grep Apple

Prints the total number of word Apple

cat gautam.txt | grep Apple | wc -l

Prints the total number of line that contains Apple word

cat /etc/passwd | grep gautam | cut -d: -f6

Prints the home directory for gautam user

How:

  1. Cut the whole line from :  (-d is delimiter where do you want to make this cut)
  2. Takes the field from 6th position

grep -E ^M gautam.txt

Match everything in line that starts with letter M

-E = find pattern as an extended regular expression

grep -E “apple?” gautam.txt

Search anyline that ends with apple

$ = match end of line

grep -E “apple|ball” gautam.txt

Search for either result via |

grep -E “Ap*le” gautam.txt

In line; Match an A followed by zero or more ps followed by le. // doesn’t have to be line start with a, it searches in line and not from the beginning of the line

grep -E “Ap+le” gautam.txt

In line; Match an A followed by one or more ps followed by le. // doesn’t have to be line start with a, it searches in line and not from the beginning of the line

grep -E “Ap?le” gautam.txt

Match an A followed by maybe more ps followed by le.

grep -E “Ap[p-z]le” gautam.txt

Match an A followed by p through z followed by le.

Hardware Command - 6

df -h

How much storage is available

Disk free -h(human-readable)

cat /proc/cpuinfo

lscpu

sysctl -n hw.ncpu OR sysctl -a | grep machdep.cpu // for mac OS

How many CPUs/cores

CPU speed (model name)

sudo dmidecode

sudo lshw

Info about motherboard // under memory device you’ll find size = RAM

free -m

Howmuch swap is being used // IMP

sudo lshw

BIOS version

Lshw pull infor about montherboard

du -sh DIR_NAME

To check the size of the directory

du = disk usage

mount ABSOLUTE_PATH /mnt

mount downloads/work /mnt

To mount on disk

Network Commands - 7

Ifconfig

View and change the interface configuration 

sudo ip addr show

To determine the IP address

  1. Loopback device(internal device used by linux)
  2. eth0(actual NIC)
  • return IP address of the host
  • Returns MAC address // link/ether

ping -c1 www.google.com 

curl -I www.google.com 

Connect to google server | test connectivity

To make the connection  // make sure the DNS is working correctly

sudo ip route show OR ip r s

Determine the gateway

cat /etc/resolv.conf OR cat /etc/resolv.conf | grep nameserver

Determine DNS server (Name Server)

  • This is the host that any DNS query going to go to

dig www.nike.com

Translet domain name to IP address with more info (question[give me internet record] section and answer section)

host www.nike.com

Translet domain name to IP address | DNS lookup using configured DNS

  • Use Host for Lightweight DNS work

dig @1.1.1.1 www.nike.com OR

dig www.nike.com 1.1.1.1

If you can’t ping google.com tell some other (external)DNS address to perform the lookup for you AND this also means your own DNS is borken and that is fixed in /etc/resolv.conf

netstat AND ss

netstat -tulpn

View listing service and active connections

  • Destination
  • Gateway
  • genmask , flags, etc

Find and determine network configuration

User/Permission Command - 8

cat /etc/passwd

List of users in linux

su - User_Name

Change from one user to another

sudo cat /etc/sudoers

See what permission assigned to all users

sudo visudo

To edit permission file

sudo su -

To go to sudo user from your user

Id gautampambhar OR cat /etc/group OR

Groups

What group a user belong to

Getent passwd gautampambhar OR

cat /etc/passwd | grep gautampambhar

What is user’s home directory

  • Return /bin/bash                        

sudo /etc/shadow

To see the password hash of the users

sudo useradd gautam2

sudo passwd gautam2

To add a new user

  • Asked for the current user password

Set a password of a new user

sudo useradd -m gautam3

Ideal way to create a user with having following        

  • -m = home directory                 

sudo groupadd admins

sudo usermod -a -G admins gautam3

Add a group

Add user to a group

  • -a: add/append
  • -G: group

You have to logout and log back in to see yourself into this group or reload profile( . /etc/profile)

sudo passwd -l User_Name

Blocking user account password

  • -l = locking

sudo userdel User_Name

Delete user

sudo chown -R user:group /home/deletedUser

Replace new user to the group with the deleted user’s group

When you create user

When you create group

Applications

Desktop application

Server applications

Server provides client services

Ex: apache, nginx (free open source web server)

Nginx  

Programming language, For example, C#, Bash, Python, etc

Chronology of source code to executable file

  1. You write code in C; your source code in C
  2. You then use a compiler to compile that code into binaries 
  3. Binary then is executable ex: firefox

Package management tool

Issue: application needs to install dependencies which also depend on other dependencies

Resolve:  package manager like apt-get and yum, which installs the complete dependencies/applications that applications need

How?: It downloads the library and packages from the software repository and installs on the host machine

Ex:

  1. dpkg: debian package
  1. Apt-get: allows automated update and package dependency management to solve problem of dependencies hell for debian linux distro
  1. rpm
  1. Yum: allows automated update and package dependency management to solve problem of dependencies hell for redhat linux distro

CLI

How it works 

$ stands for ready to take user input

CLI Syntax

Command [option] [file]

Ex: ls -l

How it works

Variables 

To store value (number, character, string) and reference it later

Use case

  1. a=”hi”
  2. Use variables to store output from certain commands
  1. a=$(ls)

Quoting

Methods of quoting

  1. Escape character: preserves the literal value of the next following character  
  2. Single quotes: preserve the literal value of variable        
  1. Ex: echo “this is $a” // “this is $a”  // It won't print the value of $a
  1. Double quotes: preserves the literal value of most characters contained within quotes, exception includes $, ‘,\
  1. Ex: echo “this is $a” // “this is gautam”  // It will print the value of $a
  2. Ex: echo “this is a \”quotes\”” //  this is a ”quotes” // preserves “”

Path environment variable

Example for quoting in Bash

  1. This is ‘just’ a “text”
  1. Echo “This is ‘just’ a \”test\”” // escape “” by putting \ in front of “
  1. this is a backslash "\" and this is a single quote'
  1. Echo “this is a backslash \”\\\” and this is a single quote'” // escape “ and \ by putting \ in front of “ and \
  1. 3 double quotes “””, and 3 single quotes ‘’’, and three backslashes \\\
  1. Echo “3 double quotes \“\”\”, and 3 single quotes ‘’’, and three backslashes \\\\\\\\\”

        In a nutshell if you want to use \ just the way it is; use \\ for escapting it

  1. This is a newline character \n, it will create a new line
  1. Echo “This is a newline character \\\n, it will create a new line”

Man & Info command for Help

To get more info about command use Man and Info command

Ex:

  1. man ls
  2. /lines // to search a keyword in the man page use /word

Linux directories and file system

We have a hard drive in our computer

When we install linux OS, it will put a file system on a hard drive and place file on that file system

It will put a file system in a specific hierarchy

Linux OS

It’s hardware(a physical component used for computing) and a Linux kernel fitted on hardware

Computing hardware

  1. CPU: processes computer function and performs calculation
  2. RAM: high performance and volatile storage
  3. Secondary storage: SSD/HDD/CVD - persistent storage for data not currently in use
  4. Network interface card: permits connection to a network
  5. Input device: Mouse/Keyboard - send data into the computer via human interaction  
  6. Output device: monitor - send info from computer to the user

Drivers:

 Cron

Internet, Network and Routers

Idea 

Command 

DNS 

It’s going to tell your Name Server that(we asked to perform a query) please translate nike.com into IP address

Network configuration

Scenario

  1. If you are on a local network on some device and want to talk to device in the same network, that request doesn’t has to be go through gateway, you can talk directly through the local network (via switch)

User and Groups

3 types of user

  1. Root user
  2. Standard user
  3. System user(service account)

Permissions

chown: it lets us change the user & group that owns the file  

chmod: let us change the mode read, write & execute across user, groups and everyone

Linux - LFCS

Essential Command

Find/Locate

What: search for files and directories.

How 

  1. Find:
  1. Search files and directories
  2. Can search by file name, type, timestamp, and other attribute
  3. Searching in realtime, so it can be slow on machine

        

find -name “file.txt”

Will search for a file in a current directory

find / -name “file.txt”

Will search for a file in root directory

find /users/hustler -name “file.txt”

Will search for a file in specified directory

find / -iname “file.txt”

To make search case insensitive

find / -type f -name “*.log”

type c

type d

type l

type f

Search type of different files

C = find input devices

D= directories

L = Links

F = files

find /etc -type f -user “hustler”

Find type by users // which user contains what files in the /etc directory

  1. locate:
  1. Faster search then find
  2. Limited search option; can’t search by attributes or metadata
  3. Relies on a database for the search, which must be refreshed regularly  

locate “file.txt”

Will search for a file and will return file with address

locate -i “file.txt”

To make search case insensitive

which/whereis/type

Which

Whereis

Type 

which python

which nano

Will return the python location

Will return the nano location

whereis python

whereis python | tr “ ” ‘\n’

Will return the python location with more details

Print all entry in a new line

tr = transmit into new line

type python

Where is python located = same as which

File Systems

Block device: media used to store data(SSD, Hard disk, floppy disk)  

File system: method of allowing OS to interact with data on a block device

FS with journaling

What: it helps prevent data loss and file corruption when you lose power.

How

Type of file systems

  1. EXT1/2/3: extended file system created for Linux in 1992
  1. Ext4: increased filesytem size, journal checksum  
  1. BTRFS: BetterFS or ButterFS created by oracle in 2007
  1. Includes FS expansion and reduction
  2. Replacement of EXT2/3/4
  1. ReiserFS
  1. Founded in 2001
  2. Dev killed his wife and development stalled
  1. ZFS: created by sun microsystem for solaris now owned by oracle
  1. Supports drive pooling, FS snapshots, FS stripping
  2. Each file has a checksum, making it easy to tell if the file has been corrupted  
  1. XFS
  1. Can be extended dynamically on the fly. However it can’t be reduced dynamically
  1. FS has to be unmounted before you reduce its size  
  1. Handles large file well
  1. JFS
  2. SWAP: this is not a file system
  1. Used to format a drive, but not technically a filesystem.
  2. Used for virtual memory (memory swapping) and doesn't have a viewable structure
  3. Temporary place for items in memory to be stored in low RAM situations
  1. FAT/32/exFAT

Manipulate File Content

cat file.txt

Print the file content

cat file.txt | more/less/sort

Cat with

More: advance the output one screen at a time

Less: advance the output one screen at a time;

  • scroll up-down one line at a time,
  • can find keyword from the text(by /type keyword),
  • monitor file in a real time(monitor log file at the time of being written) // sudo less +F var/log/syslog

 

cat file.txt | sort

sort -r file.txt

Sort file content alphabetically // will not modify file content

Sort file in reverse oerder

sort file.txt > file.txt

Write output to the file

touch file.txt

Create a new file

nano file.txt

Create and open a new file

diff file1.txt file2.txt

diff -c file1.txt file2.txt

View difference between file content

C = change

A = add

D = delete

-c = context // will give more output on the file content to review

dif ../shopping ../data/shopping

To perform directory comparison

It performed file comparison in one directory to matching files in the second directory and generate report on differences

comm file1.txt file2.txt

Compare two sored files line by line

Output will be in 3 colmuln

cmp file1.txt file2.txt

Compares 2 files, byte by byte, returns the position of first difference

Redirection operators

stdin (0) - standard input

stdout (1) - standard output

Stderr (2) - standard error

How data is entered or presented for processing Typically the keyboard or mouse, but could also be a file

The data returned from a command

Error messages that are returned, kept separate from stdout

pipe

Ex: cat file.txt | sort | head -10

Output of the cat will be sent to sort and that will forwarded to head // displays first 10 lines

> (create/overwrite)

Used to write command output to the file

will create a file if it doesn't exist, or will overwrite an existing file:

>> (create/append)

Used to append command output to a file

will create a file if it doesn't exist, or add output to an existing file

< (input)

Ex: less < file.txt

Used to direct the contents of a file to a command

Often used to send data to a script for processing but works with commands too:

Regular Expression - Regex

What: A regular expression, often referred to as regex or regexp, is a specific series of characters which are used to define a search pattern.

Why: A regex is most often used for "find all" or "find and replace" activity. It is also used when you only know part of a search string, or if you are using a wildcard search.

 

Regex basic

^

The start of a string or line

$

The end of a string or line

.

Wildcard which can match any character, except newline (\n)

|

Matches a specific character or group of characters on either side (e.g. alb corresponds to a or b)

\

Used to escape a special character

t

The character "t"  

az

The string "az"

Regex Examples

grep ‘^The’ file.txt

grep ‘^T[a-z]^e’ file.txt

grep ‘^T[a-z][^e]’ file.txt

grep ‘\<[tT]he\>’ file.txt

Print line that starts with “The”

Print line that starts with “T”, followed by a lower case from a to z, and does not end with  “e”

Return every The in the file, doesn’t matter the letter(can be uppercase or lowercase)

grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-zo-9.-]+\[A-Za-z]{2,6} \b" file.tx

print out email address in the file

Archive/Backup/Compress/Decompress

sudo tar cvf mybackup.tar DirPath

sudo tar cvf mybackup.tar /home/work/toarhive

backup files; FilePath should be full path

c=create

v=verbose

f=file

  • This tar will have same amount of space those files contains.         

sudo tar cvfz mybackup.tar.gz DirPath

Compress files

z=zip

  • This will be smaller in size

Tar tf archive.tar

Look through/List files in the archive.tar

Tar xvf archive.tar file3

Tar xvf archive.tar // extract everything

Extract specific file from the archive.tar

touch file.txt

nano file.txt

ls -lhF > file.txt

Create a file.

Create and open file

Create a file.

  1. cp -v demo(file) folder(folderName)

  1. cp demo demo2
  2. cp demo demo2 demo3 folder(folderName)
  3. cp -i demo folder(folderName)
  4. cp -iv demo folder
  5. cp -iv demo ..
  1. Copy the file into the given directory/folder at last. -v stands for verbose, it prints copied file into mentioned folder on the command line  
  2. Copy the the existing file(demo) and give a new name at last of copied file // rename and create a new file
  3. Copy multiple files inside folder name you provide at last
  4. If you copy an existing file inside a foldr, -i will ask you to overwrite the file. -i stands for interactive option
  5. Use multiple option together (overwrite & verbose)
  6. Copy file to previous directory

mv -v play/demo.txt .

Moves the file from play folder into current directory

mv demo NewName.txt

Rename file from demo to NewName.txt

  1. rm -v demo
  2. rm -v -r folder
  3. rm -i demo
  1. Remove file // remove means it is deleted forever, can’t find in the trash
  2. Remove folder
  3. Remove with interactive mode

Hard/Soft Links

Task: As an admin, how can you handle the need for a file to be accessible in two places at the same time? Let's look at hard and soft links as an option.

Hard Link

Soft Link (Symbolic Link)

ln info.txt infohardlink

Create a hard link

  • This will create a hardlink file(which is copy of the info.txt file)
  • ls -li = hardlink shares same inode value as source file
  • So if you update hardlink file, it will automatically update the source file
  • If you delete source file, you will still has HL file

ln -s info.txt infosoftlink

Create a soft link

File Permissions

Manage access to the root account

Task: The root account has access to manage and modify the entire system. To secure and protect the system, how to we restrict access to root?

Why not root?

How to avoid root

  1. sudo - superuser do
  1. Grants temporary elevated privileges to run a command
  1. Su
  1. Substitute user
  2. Changes to the root account until logout

How to manage sudo access

Taks

sudo -i

Login as a root user

su UserName

Switch to different user

Tasks

  1. Backup App via archive by Tar

What: Team wants to take a full backup of the custom application in the /opt/myapp/ directory. back will need to be compressed. We need to create a file called myapp.tar.gz in the /home/cloud_user/archive directory.

mkdir archive
cd archive
# Archive the /opt/myapp Directory as myapp.tar.gz
tar -czvf myapp.tar.gz /opt/myapp
# List the Contents of myapp.tar.gz and Redirect It to app.list
tar -tf myapp.tar.gz
# redirect the output to an app.list file:
tar -tf myapp.tar.gz > app.list

  1. Add/Change execute permission to files and view/change attribute

Task: Correct the permissions and attributes of /opt/myapp/start.sh on the system, so the custom application located under /opt/myapp has the permission to execute. In order to prevent problems with this program, /opt/myapp/start.sh, we are also asked to set the attribute of the file, so that the file cannot be altered or removed accidentally.

# View the Current Permissions of /opt/myapp/start.sh
cd /opt/myapp
ls -l start.sh
stat start.sh
# Change Permissions on /opt/myapp/start.sh to Allow Full Privileges for User and Group Only
chmod u=rwx,g+wx,o-r start.sh
chmod 770 start.sh
# Verify That /opt/myapp/start.sh Is Executable
stat start.sh
./start.sh
# Make the /opt/myapp/start.sh Immutable Using a File Attribute
lsattr start.sh
sudo chattr +i start.sh
lsattr start.sh

  1. Finding Files, and Assigning Permissions and Ownership

Task: We need to give any members of the DevOps group write access to /opt/myapp, so that they can work on the application. We also need to give the user cloud_user ownership of the directory. DevOps members and cloud_user need to be able to execute the application, start.sh as well. Finally, we need to make sure that anyone who is not cloud_user or in the DevOps group has absolutely no access to /opt/myapp whatsoever.

# Find Custom Application Files under /opt/myapp and Display a Detailed
find /opt
find /opt/myapp -ls
# Change the /opt/myapp Directory to be Owned by the cloud_user and the Group devop
find /opt/myapp -
exec sudo chown cloud_user:devop {} \;
# Set Permissions for /opt/myapp Files
find /opt/myapp -name
"d*" -ok chmod 660 {} \;
# Next we'll change permissions on anything that does not start with d (the directory itself and the start.sh script). We're going to also prompt ourselves to confirm each change with the -ok switch:
find /opt/myapp
'!' -name "d*" -ok chmod 770 {} \;
# Find a Directory under /home Which Is Not Owned by a User or Group
find /home -nouser -nogroup -ls
# Execute the chown Command with the find Command
find /home -ls
find /home -nouser -a -nogroup -ls
find /home -nouser -nogroup -
exec sudo chown cloud_user:cloud_user {} \;

  1. Transfer Files Securely Over the Network

Tasks:

# Push copy of directory from server to server
scp -rp /opt/myapp root@server2:/opt
# Pull copy of directory from server to server
scp -rp root@server:/opt/myapp /opt
# Push copy of directory from server1 to server
rsync -aP /opt/myapi server2:/opt
# Pull copy of directory from server to server1
rsync -aP server2:/opt/myapi /opt

Operation of Running Systems

Boot, Reboot, and Shut Down a System Safely

What: A Linux machine requires maintenance for hardware and OS updates. How should you shut down or reboot the machine?

  1. shutdown: This is the go-to command for shutting down, powering off, or rebooting a machine. It works on system 5 and system-based operating systems
  1. Reboot: It performs the same function as shutdown -r, but can also be used to halt or power off the server when the correct parameters are sent.
  2. Halt: This performs the same function as shutdown -H. And can also be used to reboot or power off the server when the correct parameters are sent
  3. Poweroff: It performs the same function as shutdown -P, and can also be used to reboot or halt the server when the correct parameters are sent

 

Linux Server Troubleshooting Guide

Methods

  1. USE: Utilization - Saturation - Error
  2. KAVBG: Knowledge - Ask Question - Visualize - Break it to replace it - Google

Commands

Load and CPU Usage

Load: uptime

CPU Usage: top/ps

Java Thread dumps: jstack

uptime

Know whether our system is overloaded

  • to find the load average values for the last 1, 5, and 15 minutes

cat /proc/cpuinfo | grep processor | wc -l

To know the number of cores we can use /proc file system:

top

provides load averages, CPUs, and their percentage utilization

ps

To know the process ID of our Java process

  • will list process IDs of those Java processes for which the tool has access permissions.

jstack

prints the stack traces of all threads that are attached to the JVM. These include application threads, VM internal threads, and optionally native stack frames. Using jstack, it is also possible to force (using –F flag) a thread dump of a hung process or when its output has been redirected such that the dumps are not available through kill –QUIT command

Scenarios

Task: To understand that our application is suffering from high CPU usage

  1. Top: note whether CPU is constantly above 85-90% CPU utilization or not. we need to isolate the root cause(s).
  2. Initiate a few thread dumps: In thread dumps, we are only interested in those threads which are keeping the CPU busy - threads which are in RUNNABLE state.
  1. Inspect the threat dump status

To, summarize, we took thread dumps and made a note of RUNNABLE threads. In parallel, we

also took output from ps command. We filtered out a great number of RUNNABLE threads from

thread dump for our analysis because we were able to find those threads which are consuming

maximum CPU.

Kernel Buffer Commands

free -m

Check RAM

top

See running processes

dmesg

dmesg | less

dmesg -T

Check kernel message if it’s printing any logs

Virtual Memory Commands

vmstate

How many resources are in queue, buffer size, swap, free memory and more  

PID Status Commands

ps

How many resources are in queue, buffer size, swap, free memory and more