Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

user/sysinfotest.c : is there a bug? #190

Open
qin-you opened this issue Jul 3, 2023 · 1 comment
Open

user/sysinfotest.c : is there a bug? #190

qin-you opened this issue Jul 3, 2023 · 1 comment

Comments

@qin-you
Copy link

qin-you commented Jul 3, 2023

int
countfree()
{
uint64 sz0 = (uint64)sbrk(0);
struct sysinfo info;
int n = 0;

while(1){
if((uint64)sbrk(PGSIZE) == 0xffffffffffffffff){ /* loop forever if there is no more mem originally?/
break;
}
n += PGSIZE; /
undercount one if there is only one page left originally ?*/
}
}

@ljluestc
Copy link

ljluestc commented Nov 4, 2023

#include <unistd.h>
#include <sys/sysinfo.h>

int countfree() {
uint64_t sz0 = (uint64_t)sbrk(0);
struct sysinfo info;
int n = 0;

while (1) {
    if ((uint64_t)sbrk(PGSIZE) == (uint64_t)-1) { /* Check if sbrk returns -1 when there's no more memory */
        break;
    }
    n += PGSIZE;
}

return n;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants