Thread: how to get used max memory to run a software

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    168

    how to get used max memory to run a software

    I have a software? for example: named Spp
    how to write a c program to get the max memory of Spp?

    thanks!

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    There is no way.

    Code:
    int main() {
        int x;
        scanf("%d", &x);
        malloc(x);
        for (;;);
    }
    What's the max memory used by this program?

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    I see!

    how to run a command every seconds?
    Code:
    the first second: exec: top -u admin
    the second second: exec: top -u admin
    the third second: exec: top -u admin
    the fourth second: exec: top -u admin

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by zcrself View Post
    I see!

    how to run a command every seconds?
    Code:
    the first second: exec: top -u admin
    the second second: exec: top -u admin
    the third second: exec: top -u admin
    the fourth second: exec: top -u admin
    Code:
    while [ 1 ] ; do
       top -u admin
       sleep 2s
    done
    ... That's not what you originally wanted though...

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by zacs7 View Post
    Code:
    while [ 1 ] ; do
       top -u admin
       sleep 2s
    done
    ... That's not what you originally wanted though...
    how to store "top -u admin" to a variable?

    char s[100];
    s = 'top -u admin'

  7. #7
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Top is reporting information and updates it automatically, which I suppose was sacs7's point with his bash script. You can set the interval to 1 second with the -i flag, I think that is pretty close to default though.

  8. #8
    Registered User
    Join Date
    Aug 2009
    Posts
    168
    Quote Originally Posted by Subsonics View Post
    Top is reporting information and updates it automatically, which I suppose was sacs7's point with his bash script. You can set the interval to 1 second with the -i flag, I think that is pretty close to default though.
    I see,
    Good!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex and Shared Memory Segment Questions.
    By MadDog in forum Linux Programming
    Replies: 14
    Last Post: 06-20-2010, 04:04 AM
  2. Memory usage and memory leaks
    By vsanandan in forum C Programming
    Replies: 1
    Last Post: 05-03-2008, 05:45 AM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. Memory leak trackers
    By Darkness in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-30-2004, 02:03 PM
  5. Managing shared memory lookups
    By clancyPC in forum Linux Programming
    Replies: 0
    Last Post: 10-08-2003, 04:44 AM