I have set this up so that any external program can determine the
amount of free memory by using popen().  The short program below
demonstrates this.


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

int main()
{
  FILE * read_fp;
  char buffer [ BUFSIZ+1];
  int chars_read;
  long int val;

  memset(buffer, '\0', sizeof(buffer));
  read_fp = popen("memview -c -v -f", "r");

  if (read_fp != NULL)
  {
    chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
    if (chars_read > 0)
    {
     if(val = strtol(buffer, NULL, 10))
       printf("You have at least %li megs of free memory\n", val);
     else
       printf("Could not computer total\n");
    }
    pclose(read_fp);
    exit(EXIT_SUCCESS);
  }

  exit(EXIT_FAILURE);
}




On Sep 25, 9:39 am, Dos-Man 64 <[email protected]> wrote:
> Ah.  OK.  Well, maybe someone can convert this over.  All of the
> source code files are in the zip file.  Right now I'm mainly
> interested if it is displaying correct totals.  I don't remember how
> much memory I put in my machine.  Windows says 442 megs or something
> along those lines, but I thought I had put more than that.  I'm also
> not sure if the total free memory is being reported correctly.
> According to this program, knoppix is used up about close to 400 megs
> of what I have.
>
> On Sep 25, 9:23 am, Jeremiah Bess <[email protected]> wrote:
>
>
>
> > Plasmoid is a widget for KDE4 desktop...The desktop software is called
> > Plasma.
>
> > Jeremiah E. Bess
> > Network Ninja, Penguin Geek, Father of four
>
> > On Fri, Sep 25, 2009 at 08:14, Dos-Man 64 <[email protected]> wrote:
>
> > > On Sep 25, 7:17 am, Jeremiah Bess <[email protected]> wrote:
> > > > I tried it on Mandriva 2009 Spring. I ran ./memview and got a dependency
> > > > issue:*
>
> > > > *
>
> > > > *[jb...@scooter memview]$ ./memview*
> > > > *./memview: error while loading shared libraries: libgtk-1.2.so.0: 
> > > > cannot
> > > > open shared object file: No such file or directory*
>
> > > > *
> > > > *I installed libgtk+1.2 (2.0 was available, but did not test it):*
>
> > > > *
>
> > > > *[jb...@scooter memview]$ sudo urpmi
> > > > libgtk+1.2                                  *
> > > > *To satisfy dependencies, the following packages are going to be
> > > > installed:      *
> > > > *   Package                        Version      Release
> > > > Arch               *
> > > > *(medium "Main
> > > > (Official2009.1-1)")                                              *
> > > > *  libglib1.2                     1.2.10       22mdv2009.1
> > > > i586                *
> > > > *(medium "Contrib
> > > > (Official2009.1-9)")                                           *
> > > > *  galaxy-gtk12                   1.0.6        2mdv2009.1    i586
> > > > (suggested) *
> > > > *  gdk-pixbuf-loaders             0.22.0       14mdv2009.1   i586
> > > > (suggested) *
> > > > *  libgdk-pixbuf2                 0.22.0       14mdv2009.1   i586
> > > > (suggested) *
> > > > *  libgtk+1.2                     1.2.10       50mdv2009.1
> > > > i586                *
> > > > *2.4MB of additional disk space will be
> > > > used.                                    *
> > > > *798KB of packages will be
> > > > retrieved.                                            *
> > > > *Proceed with the installation of the 5 packages? (Y/n) y          **
> > > > *
>
> > > > *ftp://mirrors.kernel.org/mandrake/Mandrakelinux/official/2009.1/i586/.
> > > ..
> > > > *
> > > > *ftp://mirrors.kernel.org/mandrake/Mandrakelinux/official/2009.1/i586/.
> > > ..
> > > > *
> > > > *ftp://mirrors.kernel.org/mandrake/Mandrakelinux/official/2009.1/i586/.
> > > ..
> > > > *
> > > > *ftp://mirrors.kernel.org/mandrake/Mandrakelinux/official/2009.1/i586/.
> > > ..
> > > > *
> > > > *ftp://mirrors.kernel.org/mandrake/Mandrakelinux/official/2009.1/i586/.
> > > ..
> > > > *
> > > > *installing libglib1.2-1.2.10-22mdv2009.1.i586.rpm
> > > > gdk-pixbuf-loaders-0.22.0-14mdv2009.1.i586.rpm
> > > > galaxy-gtk12-1.0.6-2mdv2009.1.i586.rpm
> > > > libgdk-pixbuf2-0.22.0-14mdv2009.1.i586.rpm
> > > > libgtk+1.2-1.2.10-50mdv2009.1.i586.rpm from /var/cache/urpmi/rpms*
> > > > *Preparing...
> > > > #############################################*
> > > > *      1/5: libglib1.2
> > > > #############################################*
> > > > *      2/5: libgtk+1.2
> > > > #############################################*
> > > > *      3/5: libgdk-pixbuf2
> > > > #############################################*
> > > > *      4/5: gdk-pixbuf-loaders
> > > > #############################################*
> > > > *      5/5: galaxy-gtk12
> > > > #############################################*
>
> > > > *
> > > > *Then I ran it again, and it worked, but with an error.
> > > > *
> > > > *
>
> > > > > *[jb...@scooter memview]$ ./memview*
>
> > > > > *Gtk-WARNING **: Failed to load module "libcanberra-gtk-module.so":
> > > > > libcanberra-gtk-module.so: cannot open shared object file: No such 
> > > > > file
> > > or
> > > > > directory*
>
> > > > It displayed on my screen, but did not update. I opened a few programs,
> > > and
> > > > it stayed at the same numbers. I then opened top and took a screenshot 
> > > > of
> > > > what I was currently at (attached). While the application looks like it
> > > will
> > > > work with a few modifications, it's actual use is questionable. I think
> > > it
> > > > might be better suited as a desktop widget or plasmoid to embed on KDE4.
>
> > > > Jeremiah E. Bess
> > > > Network Ninja, Penguin Geek, Father of four
>
> > > > On Thu, Sep 24, 2009 at 23:25, Dos-Man 64 <[email protected]> wrote:
>
> > > > > This displays total memory and free memory, either in a window or to
> > > > > stdout.
>
> > > > > Would anyone please help to test this out?  I need to make sure the
> > > > > output is correct, that all the needed files are in the zip file, that
> > > > > no segmentation faults (related to pointers) are taking place, and
> > > > > that the end user has the proper priviledges to run the executable.
> > > > > Once I am sure it is working correctly, I have to whip up a EULA and
> > > > > upload it somewhere so that people can download it.
>
> > > > >http://www.yousendit.com/transfer.php?action=batch_download&batch_id=.
> > > ..
>
> > > Jeremiah, this is not intended to update itself.  It is intended to
> > > provide you with a snapshot of what your memory situation looks like
> > > at a particular moment in time.  If you wanted to compare the output
> > > after you had run some programs to see how much memory they used, use
> > > command line redirection.
>
> > > Like this...
>
> > > $ echo running memview for the first time > memview.log
> > > $ memview -c >> memview.log
> > > $ echo running xmms and k3b now >> memview.log
> > > $ xmms
> > > $ k3b
> > > $ echo running memview for the second time >> memview.log
> > > $ memview -c >> memview.log
>
> > > What the hell is a plasmoid?   :D
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Linux Users Group.
To post a message, send email to [email protected]
To unsubscribe, send email to [email protected]
For more options, visit our group at 
http://groups.google.com/group/linuxusersgroup
-~----------~----~----~----~------~----~------~--~---

Reply via email to