Basic Memory Check question

I am writing a program that needs to check the amount of system memory
available at any one time. Is there a system call I can make that will
return the available memory space to me?

Thank you for your help.

Dave Chandler wrote:

I am writing a program that needs to check the amount of system memory
available at any one time. Is there a system call I can make that will
return the available memory space to me?

Thank you for your help.

stat("/proc", &mystatstruct);

\

Cheers,
Adam

QNX Software Systems
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

I apologize, but I don’t see an item in the stat struct referring to free
memory. I am sure I am missing something simple and obvious here. Sorry
about that.

struct stat {
#if _FILE_OFFSET_BITS - 0 == 64
ino_t st_ino; /* File serial number. /
off_t st_size; /
File size in bytes. /
#elif !defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS == 32
#if defined(LITTLEENDIAN)
ino_t st_ino; /
File serial number. /
ino_t st_ino_hi;
off_t st_size;
off_t st_size_hi;
#elif defined(BIGENDIAN)
ino_t st_ino_hi;
ino_t st_ino; /
File serial number. /
off_t st_size_hi;
off_t st_size;
#else
#error endian not configured for system
#endif
#else
#error _FILE_OFFSET_BITS value is unsupported
#endif
dev_t st_dev; /
ID of the device containing the file.
/
dev_t st_rdev; /
Device ID.
/
uid_t st_uid; /
User ID of file.
/
gid_t st_gid; /
Group ID of file.
/
time_t st_mtime; /
Time of last data modification.
/
time_t st_atime; /
Time when file data was last
accessed./
time_t st_ctime; /
Time of last file status change.
/
mode_t st_mode; /
File types and permissions.
/
nlink_t st_nlink; /
Number of hard links to the file.
/
blksize_t st_blocksize; /
Size of a block used by st_nblocks.
/
_int32 st_nblocks; /
Number of blocks st_blocksize blocks.
/
blksize_t st_blksize; /
Preferred I/O block size for object.
/
#if _FILE_OFFSET_BITS - 0 == 64
blkcnt_t st_blocks; /
No. of 512-byte blocks allocated for
a file. /
#elif !defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS == 32
#if defined(LITTLEENDIAN)
blkcnt_t st_blocks; /
No. of 512-byte blocks allocated for
a file. */
blkcnt_t st_blocks_hi;
#elif defined(BIGENDIAN)
blkcnt_t st_blocks_hi;
blkcnt_t st_blocks;
#else
#error endian not configured for system
#endif
#else
#error _FILE_OFFSET_BITS value is unsupported
#endif
};


“Adam Mallory” <amallory@qnx.com> wrote in message
news:d2h3tb$da$1@inn.qnx.com

Dave Chandler wrote:
I am writing a program that needs to check the amount of system memory
available at any one time. Is there a system call I can make that will
return the available memory space to me?

Thank you for your help.



stat("/proc", &mystatstruct);

\

Cheers,
Adam

QNX Software Systems
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

Dave Chandler wrote:

I apologize, but I don’t see an item in the stat struct referring to free
memory. I am sure I am missing something simple and obvious here. Sorry
about that.

struct stat {
#if _FILE_OFFSET_BITS - 0 == 64
ino_t st_ino; /* File serial number. /
off_t st_size; /
File size in bytes. /
#elif !defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS == 32
#if defined(LITTLEENDIAN)
ino_t st_ino; /
File serial number. /
ino_t st_ino_hi;
off_t st_size;
off_t st_size_hi;
#elif defined(BIGENDIAN)
ino_t st_ino_hi;
ino_t st_ino; /
File serial number. /
off_t st_size_hi;
off_t st_size;
#else
#error endian not configured for system
#endif
#else
#error _FILE_OFFSET_BITS value is unsupported
#endif
dev_t st_dev; /
ID of the device containing the file.
/
dev_t st_rdev; /
Device ID.
/
uid_t st_uid; /
User ID of file.
/
gid_t st_gid; /
Group ID of file.
/
time_t st_mtime; /
Time of last data modification.
/
time_t st_atime; /
Time when file data was last
accessed./
time_t st_ctime; /
Time of last file status change.
/
mode_t st_mode; /
File types and permissions.
/
nlink_t st_nlink; /
Number of hard links to the file.
/
blksize_t st_blocksize; /
Size of a block used by st_nblocks.
/
_int32 st_nblocks; /
Number of blocks st_blocksize blocks.
/
blksize_t st_blksize; /
Preferred I/O block size for object.
/
#if _FILE_OFFSET_BITS - 0 == 64
blkcnt_t st_blocks; /
No. of 512-byte blocks allocated for
a file. /
#elif !defined(_FILE_OFFSET_BITS) || _FILE_OFFSET_BITS == 32
#if defined(LITTLEENDIAN)
blkcnt_t st_blocks; /
No. of 512-byte blocks allocated for
a file. */
blkcnt_t st_blocks_hi;
#elif defined(BIGENDIAN)
blkcnt_t st_blocks_hi;
blkcnt_t st_blocks;
#else
#error endian not configured for system
#endif
#else
#error _FILE_OFFSET_BITS value is unsupported
#endif
};

You’re looking for the st_size member if you’re using stat64 or the
combination of st_size_hi and st_size when using just stat(). The /proc
‘pseudo file’ interface exports the free memory as its ‘file size’, so
using stat() on it will extract it (just like stat() on any file would
return it’s filesize).

If you do an ‘ls -ld /proc’ on the shell command line, you’ll see the
same thing.



\

Cheers,
Adam

QNX Software Systems
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>