Programatically read 'size' shown in top?


 
Thread Tools Search this Thread
Operating Systems Solaris Programatically read 'size' shown in top?
# 1  
Old 02-19-2010
Programatically read 'size' shown in top?

How can the 'size' of a process, that is shown by 'top', be read programatically?

I'm fixing a memory leak in a large (20,000 lines) program. (The main.cpp is itself 7400 lines!).
# 2  
Old 02-21-2010
Can you please elaborate the question better ?

What do you mean by SIZE ? memory ?

Through which program you want to read, through ( within ) the same CPP program or using some scripts ?
# 3  
Old 02-21-2010
Use the right tool for the job.

If this is a commerical application, a real memory-management tool like Purify is well worth the cost. How many hours have you spent trying to find this bug? Stumbling around looking here and there, hoping to find it?

No one takes their cars to be fixed by a mechanic who uses only a pair of pliers and one thirty-year-old bent screwdriver, do they? Why do they expect programmers to do their job without tools, then?

And why do too many programmers not want to use the proper tools?
# 4  
Old 02-22-2010
There are quite a lot of free and efficient tools too allowing to track down memory leaks under Solaris, including dbx run time checking.
How to find memory leak in solaris?

Back to the original question, here is a sample code to monitor a process size an rss:
Code:
#include <procfs.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
  char psinfo[32];
  struct psinfo p;
  int fd;
  pid_t pid;
  if(argc>1)
    pid=atoi(argv[1]);
  else
    exit(1);
  sprintf(psinfo,"/proc/%ld/psinfo",pid);
  fd=open(psinfo, O_RDONLY);
  if(fd!=-1)
  {
    read(fd,&p,sizeof(p));
    printf("size=%d rss=%d\n", p.pr_size, p.pr_rssize);
    close(fd);
  }

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

SSH Programatically

Hi Experts, Need some help. I am trying below code programatically to login to ssh ip from a csv file. the below code logging into all servers and executing some command line syntax. But what I need is for example if i have 5 IP's ,if first one connects successfully and executes the... (3 Replies)
Discussion started by: onenessboy
3 Replies

2. Programming

Maximum buffer size for read()

Hi friends, Hope everybody is fine. First have a look at my code, then we will talk about it. $ cat copy.c #include <stdio.h> #define PERMS 0644 /* RW for owner, R for group, others */ #define BUFSIZE 1 char *progname; int main(int argc,char * argv) { int f1, f2, n; ... (4 Replies)
Discussion started by: gabam
4 Replies

3. Shell Programming and Scripting

Script to read file size and send email only if size > 0.

Hi Experts, I have a script like $ORACLE_HOME/bin/sqlplus username/password # << ENDSQL set pagesize 0 trim on feedback off verify off echo off newp none timing off set serveroutput on set heading off spool Schemaerrtmp.txt select ' TIMESTAMP COMPUTER NAME ... (5 Replies)
Discussion started by: welldone
5 Replies

4. 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

5. UNIX for Dummies Questions & Answers

Query related to swap information shown by top command

Hi I have checked the output of top command in which there is a difference shown between the swap of top command for a process with total swap memory usage of the top command. Swap usage of process is higher than the total swap memory usage. top - 18:28:21 up 7:13, 5 users, load... (2 Replies)
Discussion started by: gagan2914
2 Replies

6. Shell Programming and Scripting

Display top ten directories by size

Hi, I am new to Unix. I want to display top 10 folders by size. I tried with du -ksl * | sort -nr | head -10 command .But I am getting the following error -bash: /usr/bin/du: Argument list too long Can some one help me. Thanks. (5 Replies)
Discussion started by: Satyak
5 Replies

7. Shell Programming and Scripting

command to read file name and size

hi all, there is any command or anything we can use to read the file name and size. thanks (6 Replies)
Discussion started by: s_linux
6 Replies

8. UNIX for Dummies Questions & Answers

Unix shell script for finding top ten files of maximum size

I need to write a Unix shell script which will list top 10 files in a directory tree on basis of size. i.e. first file should be the biggest in the whole directory and all its sub directories. Please suggest any ideas (10 Replies)
Discussion started by: abhilashnair
10 Replies

9. Programming

Add IpAddress Through Programatically

Hi all, Can u give me some suggestions how to add Ip Address through Programmatically , Actually I done it in Windows But now I want same thing in Unix................................ Can Any body Help to me....... (6 Replies)
Discussion started by: ykmraju
6 Replies

10. Shell Programming and Scripting

Please help with Top and SIZE of process

Hi, what I want to do is get the SIZE of a particular process from top into a shell script so I can put it in a while loop. I want to display a warning message when the process size gets up to a certain amount, but I don't know how to get that one line spit out from Top and thrown into my shell... (5 Replies)
Discussion started by: satraver
5 Replies
Login or Register to Ask a Question