Common debugging tools for linux system

  • gdb 调试利器: DB is a command line-based, powerful program debugging tool released by the GNU open source organization under the UNIX/LINUX operating system. For a C++ programmer working under Linux, gdb is an indispensable tool;
  • ldd 查看程序依赖库: Used to view the shared library required for the program to run. It is often used to solve some problems that the program cannot run due to the lack of a certain library file.
  • lsof 一切皆文件: Lsof (list open files) is a tool for viewing current system files. In the Linux environment, everything exists in the form of files. Through files, you can access not only regular data, but also network connections and hardware. Such as Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) sockets, etc., the system allocates a file descriptor for the application in the background, which provides a lot of information about the application itself.
  • ps 进程查看器: To monitor and control the process, you must first understand the current process, that is, you need to view the current process, and the ps command is the most basic and very powerful process view command. Use this command to determine which processes are running and running status, whether the process is over, whether the process is dead, which processes are occupying too many resources, and so on. In short, most of the information can be obtained by executing this command.
  • pstack 跟踪进程栈: This command can display the stack trace of each process. The pstack command must be run by the owner or root of the corresponding process. You can use pstack to determine where the process hangs. The only option allowed for this command is the PID of the process to be checked. This command is very useful when troubleshooting process problems. For example, we found that a service has been in work state (such as suspended animation, like an infinite loop). Using this command can easily locate the problem; you can execute pstack several times in a period of time , If you find that the code stack always stops at the same location, that location needs to be focused on, and it is likely to be the problem;
  • strace 跟踪进程中的系统调用: Strace is often used to track system calls and received signals during process execution. In the Linux world, processes cannot directly access hardware devices. When processes need to access hardware devices (such as reading disk files, receiving network data, etc.), they must switch from user mode to kernel mode, and access hardware devices through system calls. strace can track the system calls generated by a process, including parameters, return values, and execution time.
  • ipcs 查询进程间通信状态: Ipcs is a tool for displaying the status of inter-process communication facilities under Linux. Can display message queue, shared memory and semaphore information. Very useful for programmers, ordinary system administrators generally do not use this command.
  • top linux下的任务管理器: The top command is a commonly used performance analysis tool under Linux, which can display the resource occupancy status of each process in the system in real time, similar to the task manager of Windows. top is a dynamic display process, that is, the current state can be constantly refreshed by the user's keystrokes. If the command is executed in the foreground, it will monopolize the foreground until the user terminates the program. To be more precise, the top command provides real-time access to the system Processor status monitoring. It will display a list of the most "sensitive" tasks for the CPU in the system. This command can sort tasks by CPU usage, memory usage and execution time; and many features of this command can be accessed through interactive commands or Set in the personal customization file.
  • free 查询可用内存: The free tool is used to view the available memory of the system:
  • vmstat 监视内存使用情况: Vmstat is the abbreviation of Virtual Meomory Statistics (virtual memory statistics), which can dynamically monitor the virtual memory, process, and CPU activities of the operating system in real time.
  • iostat 监视I/O子系统: Iostat is the abbreviation of I/O statistics (input/output statistics), which is used to dynamically monitor the disk operation activities of the system.
  • sar 找出系统瓶颈的利器: Sar is the abbreviation of System Activity Reporter (system activity report). The sar tool will sample the current state of the system, and then express the current operating state of the system by calculating data and proportions. Its characteristic is that it can continuously sample the system to obtain a large amount of sampling data; the sampling data and analysis results can be stored in files, and the required load is very small. sar is currently one of the most comprehensive system performance analysis tools on Linux. It can report system activities from 14 major aspects, including file reading and writing, system call usage, serial port, CPU efficiency, memory usage, Process activities and IPC-related activities are also more complicated to use.
  • readelf elf文件格式分析: This tool is similar to the function provided by the objdump command, but the information it displays is more specific, and it does not rely on the BFD library (the BFD library is a GNU project, and its goal is to handle different goals through a unified interface file);
  • objdump 二进制文件分析: The objdump tool is used to display the information of the binary file, which is to let you know more about the additional information that the binary file may contain in a readable format.
  • nm 目标文件格式分析: The nm command displays information about the symbols in the specified File. The file can be an object file, an executable file, or an object file library. If the file does not contain symbol information, the nm command reports the situation, but does not interpret it as an error condition. The nm command reports numerical values ​​in decimal notation by default.
  • size 查看程序内存映像大小: View the size information of the program being mapped to the image in the memory.
  • wget 文件下载: Wget in Linux system is a tool for downloading files, which is used under the command line. It is an indispensable tool for Linux users. We often have to download some software or restore backups from a remote server to a local server. wget supports HTTP, HTTPS and FTP protocols, and HTTP proxy can be used.
  • scp 跨机远程拷贝: Scp is the abbreviation of secure copy, a command used to copy files remotely under Linux. Similar commands are cp, but cp is only copied on the local machine and cannot be cross-server, and scp transmission is encrypted. When your server's hard disk becomes read-only read only system, scp can help you move the files out.
  • crontab 定时任务: Through the crontab command, we can execute specified system commands or shell scripts at regular intervals. The unit of the time interval can be any combination of minutes, hours, days, months, weeks and above. This command is very suitable for periodic log analysis or data backup.
  • watch 监视命令 : The output result of the command can be output to the standard output device, which is mostly used for periodic execution of commands/timing execution of commands

Guess you like

Origin blog.csdn.net/a807719447/article/details/115002648