/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/


#define _KERNEL
#define OFF_POSIX_INCLUDE

#include <sys/procfs.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

#include "machine/include.h"


INTEGER64
get_usedmemory_size()
{
int pid;
int fd;
struct psinfo info;
int er;
INTEGER64 ret;
char filename[100];
	pid = getpid();
	sprintf(filename,"/proc/%i/psinfo",pid);
	fd = open(filename,O_RDONLY);
	if ( fd < 0 ) {
		return -1;
	}
	er = read(fd,&info,sizeof(info));
	if ( er < 0 ) {
		return -1;
	}
	ret = info.pr_size;
	close(fd);
	return ret*1024; 
}



