
Linux System and Process Management Commands : Part 2
nmon
nmon shows performance data about cpu, memory, network, disks, file systems, nfs, top processes, resources, power micro-partition. Command keys to show following details
m
= Memoryj
= Filesystemsd
= Disksn
= NetworkV
= Virtual Memoryr
= ResourceN
= NFSk
= kernelt
= Top-processes.
= only busy disks/procs


ps
Displays information about a selection of the active processes. Some examples of ps
is
- Display the Processes Running in the Current Shell
ps
- Display All the Currently Running Processes
ps -A
- Display All the Processes Associated with the Current Terminal
ps -T
- Display All the Processes Associated with a Particular User
ps -u UserName
- Display All the Processes Associated with a Particular User Group
ps –fG UserGroupName
Example
ps –fG root
cron
Cron allows users to run commands or scripts at a given time or date. Cron is basically used to schedule scripts to be executed periodically. The detailed explanation can be found here.
dmesg
Prints messages from the kernel ring buffer. Example, List all loaded driver
$ dmesg | less
[ 0.000000] Linux version 5.4.0-88-generic (buildd@lgw01-amd64-008) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021 (Ubuntu 5.4.0-88.99-generic 5.4.140)
[ 0.000000] Command line: BOOT_IMAGE=/vmlinuz-5.4.0-88-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro debian-installer/custom-installation=/custom find_preseed=/preseed.cfg auto preseed/file=/floppy/preseed.cfg automatic-ubiquity noprompt priority=critical locale=en_US console-setup/modelcode=evdev
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
[ 0.000000] Hygon HygonGenuine
[ 0.000000] Centaur CentaurHauls
[ 0.000000] zhaoxin Shanghai
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers'
[ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers'
[ 0.000000] x86/fpu: xstate_offset[2]: 576, xstate_sizes[2]: 256
[ 0.000000] x86/fpu: Enabled xstate features 0x7, context size is 832 bytes, using 'compacted' format.
[ 0.000000] BIOS-provided physical RAM map:
- List all Detected Devices
dmesg | grep sda
- Clear dmesg Buffer Logs
dmesg -c
- Monitoring dmesg in Real Time
watch "dmesg | tail -20"
journalctl
Journalctl is used to displaying logs from journald, systemd’s logging service. Since journald stores log data in a binary format instead of a plaintext format, journalctl is the standard way of reading log messages processed by journald.
- Display all logs
journalctl
- To display the output in reverse order with new entries first
journalctl -r
- Displays the messages that systemd generated during the last time the machine started:
journalctl -b
- Display messages for systemd network service
journalctl -u systemd-networkd
kill
Used to kill a process. Examples
- terminating process with process ID
kill [pid]
- Sending a custom signal to a process
kill -s [signal] [pid]
- List all the signal you can send
$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
- The number can also be used to send singnal
kill -s [Signal_Number] [pid]
Example
kill -s 9 [pid]
- Kill all running process in one go
kill -s KILL -1
killall
killall command kill process by process name. Lets see the examples
- Killing a process
killall [process_name]
- By-default killall is case-sensitive, use
-i
to disable case sensitivity
killall -I [process_name]
- Ask before killing process
killall -i [process_name]
- Killing a process without any messages like process does not exists
killall -q [process_name]
- Kill all process owned by a user
killall -u [user_name]
- Kill processes based on time
killall -o 5h
the above command kill process older then 5 hours. Another example the below command kill the processes less then 4 hours old.
kill -y 4h
- Make syscall returns, only after process die
kill -w [process_name]
sleep
Delay/Sleep for a specified amount of time.
sleep 10
above command make execution sleep for 10 seconds, we can aslo use suffixes like s
for seconds, for m
minuts, h
for hours.
sleep 10s
sleep for 10 second.
sleep 1h
sleep for 1 hour.
sleep 5m
sleep for 5 minutes.
wait
The wait command waits for a background process to exit. Syntax
wait [PID]
Example Use
$ sleep 30 &
[1] 40560
$ wait 40560
Another example :
ping -c10 google.com &
ping -c10 facebook.com &
ping -c10 linkedin.com &
wait
echo Done