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);
|
|
|
|
size = read (fd, buf, 240);
|
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;
|
|
|
|
}
|