Debugging in Linux is essential for troubleshooting system issues, application bugs, or network problems. Here’s a simple guide to get you started with common Linux debugging tools and techniques.
1. Checking System Logs
Linux logs are a great starting point for debugging. Logs capture events related to the kernel, applications, and services.
View Logs with journalctl
# List all processes
ps aux
# View processes in real-time
top
Find a Process by Name with pgrep
pgrep <process_name>
Debug a Process with strace
strace traces system calls made by a process.
strace -p <pid>`
Debug a Process with gdb
gdb is used for debugging compiled applications.
gdb <program_name> <pid>
- Networking Debugging Check Active Connections with netstat or ss
Using netstat
netstat -tuln
Using ss
ss -tuln
Test Connectivity with ping or curl
ping <hostname_or_ip>
curl -v http://
Check Firewall Rules with iptables or ufw
Using iptables
sudo iptables -L -v
Using ufw
sudo ufw status verbose
- Disk and Filesystem Debugging Check Disk Usage with df and du
Disk space usage
df -h
Directory size usage
du -sh <directory_name>
Check Disk Health with fsck and smartctl
Check and repair filesystem (run in unmounted mode)
sudo fsck /dev/sdX
Check disk health using smartctl
sudo smartctl -a /dev/sdX
- Memory Debugging Check Memory Usage with free and vmstat
Memory usage
free -h
System performance and memory statistics
vmstat 1 5
Analyze Memory Leaks with valgrind
valgrind --leak-check=yes ./your_program
- Kernel Debugging Check Kernel Messages with dmesg
dmesg | tail
Debug Kernel Panics with kdump
Ensure kdump is installed and configured for capturing kernel crash dumps.
sudo systemctl start kdump
Conclusion
Effective debugging in Linux requires a good understanding of system logs, processes, network, disk, and memory. Start with logs, monitor processes, trace system calls, and analyze system resources. Mastering these tools will help you quickly diagnose and resolve issues.
Top comments (1)
Good one!