Detecting memory leaks in your application (shell)

Source: Internet
Author: User

Write code--debug--fix bug

Change to change there may still be some problems that are not found, when the project volume is more prone to occur, such as memory leaks such problems, serious impact on system performance.

There are some tools on the Internet that detect if a memory leak exists in a C program, such as Valgrind.

Scripts are written to detect whether the application running in the server has a memory leak problem.

Ideas are as follows:

file 1:processlist, which is used to save the name of the application requiring memory leak detection, is managed by the file 2:testmanage, or by using the./testmanage-a app name to add or./testmanage-d app Name To remove.

3:memoryleaktest . file, main program. First, empty the file 4:rsslist (used to save the memory test results of the process ) and file 5: LeakMemory.log (to hold the name of the application that has a memory leak).

in the beginning loop 1, loop 6 times, each cycle through the file 1 all the application name-process number-status file gets the memory size, save with file 4, each cycle interval 1800 seconds, so total 2.5 hours.

at the end of the third step, according to the 6 memory size of all applications saved in file 4, the next two comparisons, if the following is greater than the previous 10%,flag variable value +1, a total of 5 times, if the flag is greater than or equal to 4, the application has a memory leak.

Shell notes:

Usage of sed:

Add the following line in the matching string: Sed-i/$str/a\ "$str _new" $filename

Add a line on the matching string: Sed-i "/$str/i\\ $str _new" $filename $str _new before one \ is escaped

Two variables with underline connection: ${STR1}_${STR2}

02.

" $str 1 " - F $str 2 $p " NP "

Match the first m row of STR1, after the column containing the str2 p, take the nth row.

Detecting memory leaks in your application (shell)

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.