Visit Our UNIX and Linux User Community


can I use command "ps" to find memory leak


 
Thread Tools Search this Thread
Top Forums Programming can I use command "ps" to find memory leak
# 1  
Old 07-24-2002
can I use command "ps" to find memory leak

1 . Thanks for everyone who reads the post first.
2 . I have a idea : whether can I use command "ps" to find which application acquire memory usually .
3 . I do not confirm whether it is correctly , then I do an experiment in Tru64 unix :
I write the simple programe a.c below :

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
char *p;

while(1)
{
p = (char *) malloc(81920);

sleep(1);
}

return 0;
}

cc -g a.c -o a.out
./a.out

then I type ps uax | grep a.out | grep -v grep every 2 seconds , I find that the RSS and VSZ increments .
4 . So I guess that maybe I can use "ps aux" command to determine whether a programe acquire memory from system usually (I activate ps command periodly using crontab).
# 2  
Old 07-24-2002
You can certainly use ps to see the size of a process as your experiment proved. But if you find a process that is growing, it may or may not have a memory leak. And if you extend your experiment to do malloc() and then free() you will probably find the process will not shrink. Freed memory is returned to the pool of memory available for another malloc, it is not returned to the os. At least that's the way every malloc() library I have seen works.
# 3  
Old 07-24-2002
1 . Thanks and regards to Perderado
2 . By the way , I find that the "ps aux" command not only find the malloc() but also find if I use mmap() and ftruncate() to increment the disk file size .More if I use shmget() continously ,ps also find the RSZ increments .
3 . But now,I have meet a problem :
I use command "dxsysinfo" (Digital unix command to display the disk usage , CPU load,free memory ,free swap) . I find the "free memory" decrease from 54%(a month ago) to 0% (now).Then I type "ps aux" ,I am surprised that all process work correctly , the used memory now is equal to the used memory a month ago ( I use "ps aux" every 30 minutes with crontab)
4 . the question is that :
If an application malloc() first and then free() continously,whether it will cause the problem I introduced above.If it is so , where can I download a memory check tool for Tru64 Unix
5 .thanks
# 4  
Old 07-24-2002
I don't know tru64 nor dxsysinfo but I can answer a few things.

First, about malloc() and free()...if a process malloc's an area then free's it...there is no problem and the process won't grow over time. But the heap area can get fragmented if lots of mallocs and frees happen for many different buffer sizes. If this happens the process may grow over time.

Your shmget() comment means that System V style shared memory may be an issue. It is possible to allocate a System V shared memory segment and then exit without freeing it. The shared memory segment will continue to exit but no process is attached to it. At some point in the future, a process could attach to it if the process had the key. Meanwhile the segment is taking virtual memory at least. And it could have been locked into core. The command "ipcs" can display these. And the command "ipcrm" can remove them.
# 5  
Old 07-24-2002
thanks .
# 6  
Old 07-31-2002
Lightbulb

You can try Valgrind to find memory leaks.

Previous Thread | Next Thread
Test Your Knowledge in Computers #601
Difficulty: Medium
Consider the Unix command sequence ps aux | grep -iv apache2 | wc -l This command will output the total number of apache2 processes running.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Find lines with "A" then change "E" to "X" same line

I have a bunch of random character lines like ABCEDFG. I want to find all lines with "A" and then change any "E" to "X" in the same line. ALL lines with "A" will have an "X" somewhere in it. I have tried sed awk and vi editor. I get close, not quite there. I know someone has already solved this... (10 Replies)
Discussion started by: nightwatchrenba
10 Replies

4. Shell Programming and Scripting

Problem with "find" and "grep" command

I want to list all files/lines which except those which contain the pattern ' /proc/' OR ' /sys/' (mind the leading blank). In a first approach I coded: find / -exec ls -ld {} | grep -v ' /proc/| /sys/' \; > /tmp/list.txt But this doesn't work. I got an error (under Ubuntu): grep:... (5 Replies)
Discussion started by: pstein
5 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Retrieve RAM memory size from "top" command output

Hi, I am trying to get the system RAM size from "top" command's output by the following but it is not working. top | sed "s/^Mem.**\(*\), *//" (10 Replies)
Discussion started by: royalibrahim
10 Replies

7. UNIX for Advanced & Expert Users

command for recently modified files - "find" command not working

I have three files a.txt , b.txt , c.txt in a directory called my_dir1 .These files were created before two or three months . I have a tar file called my_tar1.tar which contains three files a.txt , b.txt , d.txt . Somebody untarred the my_tar1.tar into my_dir1 directory. So existing two files were... (1 Reply)
Discussion started by: joe.mani
1 Replies

8. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

9. Shell Programming and Scripting

"find command" to find the files in the current directories but not in the "subdir"

Dear friends, please tell me how to find the files which are existing in the current directory, but it sholud not search in the sub directories.. it is like this, current directory contains file1, file2, file3, dir1, dir2 and dir1 conatins file4, file5 and dir2 contains file6,... (9 Replies)
Discussion started by: swamymns
9 Replies

10. UNIX for Dummies Questions & Answers

Command for "Resident memory Size"

Hi Everyone.- Coul you tell me how to obtain the "Resident memory size" for any program runs on Dec TRU64 machine. What is the command in order to obtaing this value?? Best Regards Cristobal (1 Reply)
Discussion started by: Cristobal Perez
1 Replies

Featured Tech Videos