Linux debugging command (리눅스 디버깅 커맨드)

2025. 2. 22. 03:41Embedded Development

Linux Debugging Commands You Should Know

1. Checking Process and System Status

  • top / htop : Monitor real-time process CPU and memory usage
  • ps aux : View a list of running processes
  • pidstat : Analyze CPU usage of a specific process
  • vmstat : Monitor system performance and resource usage
  • iostat : Check disk I/O status
  • free -m : Check memory usage
  • uptime : Display system uptime and load average

2. Checking and Analyzing Logs

  • dmesg | less : View kernel logs (boot, drivers, hardware issues, etc.)
  • journalctl -xe : View system logs (for systemd-based environments)
  • tail -f /var/log/syslog : Monitor system logs in real-time
  • cat /var/log/messages : View general system logs
  • grep "error" /var/log/syslog : Search logs for specific keywords

3. Network Debugging

  • ping <IP> : Check network connectivity
  • traceroute <IP> : Trace network route
  • netstat -tulnp : View open ports and network connections
  • ss -tulnp : Faster alternative to netstat
  • lsof -i :<port> : Check which process is using a specific port
  • tcpdump -i eth0 port 80 : Capture network packets
  • wireshark : GUI-based network packet analysis tool
  • ifconfig / ip a : Check network interface status

4. File and Directory Debugging

  • ls -lah : Display detailed file and directory information
  • stat <filename> : Check file attributes and timestamps
  • df -h : Check disk usage
  • du -sh <directory> : Check the size of a specific directory
  • find /path -name "*.log" : Search for specific files
  • inotifywait -m <file> : Monitor real-time file changes

5. Memory and Process Debugging

  • strace -p <PID> : Trace system calls of a process
  • ltrace -p <PID> : Trace library function calls of a process
  • gdb <executable> : Debug programs with GNU Debugger
  • valgrind --leak-check=full ./program : Detect memory leaks
  • pmap -x <PID> : Check memory mapping of a process
  • cat /proc/<PID>/maps : View memory mapping details

6. File System and Disk Checking

  • fsck /dev/sdX : Check and repair filesystem errors
  • mount | grep <directory> : Check mounted filesystems
  • blkid : Check disk UUID and type
  • hdparm -I /dev/sdX : Get disk information
  • smartctl -a /dev/sdX : Check S.M.A.R.T. disk health status

7. CPU and Performance Profiling

  • perf top : Monitor real-time CPU performance
  • perf record -g ./program && perf report : Performance analysis and reporting
  • time ./program : Measure execution time
  • mpstat -P ALL : Check per-core CPU usage

8. Kernel Debugging

  • cat /proc/cpuinfo : Check CPU information
  • cat /proc/meminfo : Check memory information
  • lsmod : View loaded kernel modules
  • modinfo <module_name> : Get details of a specific kernel module
  • insmod <module.ko> / rmmod <module_name> : Load and unload kernel modules

9. Debugging Tools

  • gdb : GNU Debugger
  • valgrind : Memory leak detection and performance analysis tool
  • rr : Reverse debugging tool
  • SystemTap : Dynamic kernel analysis tool
  • bpftrace : eBPF-based performance analysis

Using these commands depending on your debugging needs will help you troubleshoot issues effectively! 🚀