2001-05-25 21:00:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2002-05-09 16:07:33 +00:00
|
|
|
#include <string.h>
|
2001-05-25 21:00:07 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
int
|
|
|
|
vmsize ()
|
|
|
|
{
|
|
|
|
int pid, fd, size, i, mem;
|
2001-05-25 21:00:07 +00:00
|
|
|
char filename[17], buf[256], *ptr, *end;
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
pid = getpid ();
|
|
|
|
snprintf (filename, 17, "/proc/%d/stat", pid);
|
|
|
|
fd = open (filename, O_RDONLY);
|
2004-04-16 10:17:55 +00:00
|
|
|
if (fd == -1) {
|
|
|
|
fprintf (stderr, "warning: could not open %s\n", filename);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-03-13 15:27:01 +00:00
|
|
|
size = read (fd, buf, 240);
|
2004-04-16 10:17:55 +00:00
|
|
|
if (size == -1)
|
|
|
|
return -1;
|
2001-05-25 21:00:07 +00:00
|
|
|
ptr = buf;
|
2004-03-13 15:27:01 +00:00
|
|
|
for (i = 0; i < 22; i++)
|
|
|
|
ptr = (char *) strchr (ptr, ' ') + 1;
|
|
|
|
end = (char *) strchr (ptr, ' ');
|
2001-05-25 21:00:07 +00:00
|
|
|
*end = 0;
|
2004-03-13 15:27:01 +00:00
|
|
|
sscanf (ptr, "%d", &mem);
|
|
|
|
close (fd);
|
2001-05-25 21:00:07 +00:00
|
|
|
return mem;
|
|
|
|
}
|