________________________________________________________________________
Applicable Environment
________________________________________________________________________
- Topic: Detect total *Free* Ram in system (Code Sample)
- SDP: 6.5.0
- Target: Any supported target
________________________________________________________________________
Recommendation
________________________________________________________________________
To obtain the total *free* system memory from code you will need to open /proc (special file) and get a stat on the fd returned (ls -l / will yield the same value). Here is a simple example on how this can be done.
static uint64_t get_total_free_mem(void)
{
int fd;
char *buffer = "/./proc";
struct stat64 st;
if ((fd = open64(buffer, O_RDONLY)) == -1)
{
fprintf (stderr, "couldn't open %s: %s\n", buffer, strerror(errno));
_exit (0);
}
if (fstat64(fd, &st) == -1)
fprintf (stderr, "couldn't get stat info for %s: %s\n", buffer, strerror(errno));
if (close (fd))
fprintf (stderr, "couldn't close fd %s", buffer);
return st.st_size;
}
________________________________________________________________________
NOTE:
This entry has been validated against the SDP version listed above. Use
caution when considering this advice for any other SDP version. For
supported releases, please reach out to QNX Technical Support if you have any questions/concerns. ________________________________________________________________________