Diagnosis of c-c++ software under Linux

Source: Internet
Author: User
Tags mysql command line

In general, C + + write programs due to memory, pointers and other issues in the late process are generally encountered memory and other resources leakage, crashes and other issues, for these problems, generally from which angle to solve?

Here is a summary from several perspectives:

Memory leaks

One of the first things to note is that top or htop shows the memory usage cache problem, which differs from what the Task Manager in Windows sees.

The specific analysis is as follows:

When Linux reads and writes files, it is used to cache disk blocks on a physical disk, which speeds up access to data on disk.

The contents of the buffer cache correspond to a block on the disk (block), usually 1 K, and are contiguous. Under Linux, for more efficient use of physical memory, the operating system automatically uses all free memory as buffer cache. When the program requires more memory, the operating system automatically reduces the cache size. When we look at the memory usage of Linux, we don't have to worry about too little memory as long as we don't see swap space. http://blog.csdn.net/heizistudio/article/details/25125061

For example, Htop displays the data, where the mem item is sometimes used up when running, and does not indicate a program leak occupancy, check the memory usage of the RES entry for the real process project, this is in use, or execute pmap-d a process number, or you can view

[Htop also provides an intuitive view of thread conditions]

With these problems, do we have a better way to avoid them? The answer is:

Ø Smart pointer

N C + + 11 standard has been, STL auto_ptr try to avoid it

N Boost share_ptr is commonly used

N Double-edged sword, using this in a specific scenario, resource consumption is less efficient than the pure new delete efficiency

File Resource Disclosure

Ødf-k/##

n If the operation file is read and written repeatedly in a directory, you can see the information that is being used and used, so that you can see if any files are not closed

Ølsof

n A tool that lists current system open files

n lsof-p PID

N http://blog.csdn.net/guoguo1980/article/details/2324454

Øfuser

n is used to display all process information that is using the specified file, file system, or sockets

N http://www.cnblogs.com/yuboyue/archive/2011/07/18/2109838.html

View Netstat SS for network information

Http://stackoverflow.com/questions/11763376/difference-between-netstat-and-ss-in-linux

http://blog.163.com/[email protected]/blog/static/132229655201222502510543/

Procfs

Windows has the Sysinternals tool, very convenient to monitor the widnows files, network, registry and other access; Linux's more powerful weapons, but all files, look a bit troublesome, used to more powerful features.

http://blog.csdn.net/jeek566/article/details/8695240

MySQL leaks

The MySQL command line can be initially viewed as follows:

[Email protected]:~# mysql-uroot-proot

Warning:using a password on the command line interface can is insecure.

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is 28

Server version:5.6.21 MySQL Community Server (GPL)

Copyright (c), the Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of the Oracle Corporation and/or its

Affiliates. Other names trademarks of their respective

Owners.

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.

Mysql> show Processlist;

+----+-------+-----------+--------+---------+------+-------+------------------+

| Id | User | Host | db | Command | Time | State | Info |

+----+-------+-----------+--------+---------+------+-------+------------------+

| 28 | Root | localhost | NULL |    Query | 0 | init | Show Processlist |

+----+-------+-----------+--------+---------+------+-------+------------------+

3 Rows in Set (0.00 sec)

If show processlist shows a growing number of data, the software is a link leak, C + + processing is best used cppdb these have connection pool processing third-party library acceleration

If you want to check more detailed information monyog This tool can be used

Crash Analysis

Leak Analysis Tool

Http://www.cnblogs.com/2018/p/3228174.html

Http://www.cnblogs.com/2018/p/3230736.html

A problem locating the execution file crash published under Linux

Http://www.cnblogs.com/2018/p/3010691.html

Http://www.cnblogs.com/2018/archive/2012/05/18/2503897.html

Performance tuning

After the problem, how to improve the performance of the system, at this time remember the 8/2 principle, the first modification is the key path of the part

Http://www.cnblogs.com/2018/p/3380773.html

Diagnosis of c-c++ software under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.