Instructor: Sir Shafan Khaliq Subject: System Network & Integration
Instructor: Sir Shafan Khaliq Subject: System Network & Integration
Instructor: Sir Shafan Khaliq Subject: System Network & Integration
Background Processes
A background process runs without being connected to your keyboard. If the background process requires any
keyboard input, it waits. The advantage of running a process in the background is that you can run other
commands; you do not have to wait until it completes to start another! The simplest way to start a background
process is to add an ampersand (&) at the end of the command.
A daemon (also known as background processes) is a Linux or UNIX program that runs in the background.
Almost all daemons have names that end with the letter "d". For example, httpd the daemon that handles the
Apache server, or, sshd which handles SSH remote access connections. Linux often start daemons at boot time.
MONITORING SYSTEM
PERFORMANCE
We will introduce you to a few free tools that are available to monitor and manage performance on Linux/Unix
systems. These tools also provide guidelines on how to diagnose and fix performance problems in the
Linux/Unix environment.
Linux/Unix has following major resource types that need to be monitored and tuned −
• CPU
• Memory
• Disk space
• Communications lines
• I/O Time
• Network Time
• Applications programs
MONITORING SYSTEM
PERFORMANCE
Performance Components
User State CPU
The actual amount of time the CPU spends running the users’ program in the user state. It includes the
time spent executing library calls, but does not include the time spent in the kernel on its behalf
System State CPU
This is the amount of time the CPU spends in the system state on behalf of this program. All I/O
routines require kernel services. The programmer can affect this value by blocking I/O transfers
MONITORING SYSTEM
PERFORMANCE
I/O Time and Network Time
This is the amount of time spent moving data and servicing I/O requests
Virtual Memory Performance
This includes context switching and swapping
Application Program
Time spent running other programs - when the system is not servicing this application
because another application currently has the CPU
MONITORING SYSTEM
PERFORMANCE
Performance Tools
Linux provides following important tools to measure and fine tune Unix system performance
nice/renice
netstat
Prints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
Netstat is a command line tool for monitoring incoming and outgoing network packets statistics as well as interface
statistics. It is very useful tool for every system administrator to monitor network performance and troubleshoot
network related problems.
Listing all the LISTENING Ports of TCP and UDP connections
# netstat -a | more
MONITORING SYSTEM
PERFORMANCE
Listing TCP Ports connections
# netstat –at
# netstat –au
# netstat –l
# netstat –s
# netstat -tp
MONITORING SYSTEM
PERFORMANCE
ps
ps stands for process status and widely used command to get a snapshot of the running process. Very
useful to find out if a process is running or not and if running then prints PID.(A process is given a
unique number called process ID (PID) that identifies that process to the system)
vmstat
Linux VmStat command used to display statistics of virtual memory, kernerl threads, disks, system
processes, I/O blocks, interrupts, CPU activity and much more.By default vmstat command is not
available under Linux systems you need to install a package called sysstat that includes a vmstat
program
#vmstat
MONITORING SYSTEM
PERFORMANCE
top
Linux Top command is a performance monitoring program which is used frequently by many system administrators to monitor Linux
performance and it is available under many Linux/Unix like operating systems. The top command used to display all the running and active
real-time processes in ordered list and updates it regularly.
#top (display task, memory, CPU and swap)
Display Specific User Process
# top -u user
Highlight Running Process in Top
Press ‘z‘ option in running top command will display running process in color which may help you to identified running process easily.
Kill running process with argument ‘k’
You can kill a process after finding PID of process by pressing ‘k‘ option in running top command without exiting from top window
MONITORING SYSTEM
PERFORMANCE
Save Top Command Results
# top -n 1 -b > top-output.txt
Getting Top Command Help
Press ‘h‘ option to obtain the top command help.
MONITORING SYSTEM
PERFORMANCE
sar
sar (System Activity Report) will be helpful to collect a number of a report including CPU, Memory, and device load.
By just executing sar command will show you system utilization for the entire day.
Show Memory usage report
# sar –r
iostat
iostat stands for input-output statistics and often used to diagnose a performance issue with storage devices. You can monitor
CPU, Device & Network file system utilization report with iostat.
iostat –d(display disk I/O statics)
iostat –c(display CPU statics)
MONITORING SYSTEM
PERFORMANCE
Kill
Terminates a process
pgrep
Finds a process based on its PID
ps commmanad with different options
First, let’s look at the processes the root user currently owns by using the ps commmand
# ps
MONITORING SYSTEM
PERFORMANCE
The ps command includes a number of options for producing different types of output, including
viewing all processes currently running on the system. To view processes with more detailed
information, you can use the following commands:
# ps u
(This command not only display the PID, but also the CPU and memory utilization)
# ps aux | grep ssh
# ps aux (could also use this command)
( I can get more detail information about a particular process)
MONITORING SYSTEM
PERFORMANCE
Let’s also look at some of the other options the ps command offers:
# ps –help (this command display more different options)
If you want to stop the SSH service because it isn’t responding, you just have to look for the PID associated with the SSH
daemon.
Syntax: kill PID
Example: kill 4282
Sometimes if the kill command doesn’t work the way you intended it to, you can also call it with the -9 option to give it priority on
the system: kill -9 Meaning: The process will be killed by the kernel; this signal cannot be ignored. 9 means KILL signal that is
not catchable or ignorable.
# kill -9 4286 Kill will generate a SIGTERM signal asking a process to kill itself gracefully i.e , free memory or take care of other
child processes. ... Kill -9 generates a SIGKILL signal which won't check the state of the process and kills the process immediately
MONITORING SYSTEM
PERFORMANCE
To find the PID(s) belonging to the SSH service, use the following:
# pidof sshd (sshd service name)
# pgrep sshd (could also use this command)
Shows real-time information about the system resources.
# top
(You can use the q to quit from the top command.)
You can use the renice command to give that particular process higher priority on the CPU.
Syntax: renice [options]
-p PID Changes process priority for a particular PID -u user Changes process priority for a particular users