test-sysconf.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <unistd.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. void sc_print()
  5. {
  6. long sc_memprot = sysconf(_SC_MEMORY_PROTECTION);
  7. long sc_shell = sysconf(_SC_SHELL);
  8. long sc_page_size = sysconf(_SC_PAGE_SIZE);
  9. long sc_pagesize = sysconf(_SC_PAGESIZE);
  10. long sc_physpages = sysconf(_SC_PHYS_PAGES);
  11. long sc_avpages = sysconf(_SC_AVPHYS_PAGES);
  12. printf("sysconf(_SC_MEMORY_PROTECTION) = %ld\n", sc_memprot);
  13. printf("sysconf(_SC_SHELL) = %ld\n", sc_shell);
  14. printf("sysconf(_SC_PAGE_SIZE) = %ld\n", sc_page_size);
  15. printf("sysconf(_SC_PAGESIZE) = %ld\n", sc_pagesize);
  16. printf("sysconf(_SC_PHYS_PAGES) = %ld\n", sc_physpages);
  17. printf("sysconf(_SC_AVPHYS_PAGES) = %ld\n", sc_avpages);
  18. }
  19. int main( int argc, char *argv[] )
  20. {
  21. int * p;
  22. int i;
  23. sc_print();
  24. printf("\nallocated %d kB\n", 4096*sizeof(int) );
  25. p = (int*)malloc( 1024 * 4096 * sizeof(int) );
  26. sc_print();
  27. printf("\ninitialized memory\n");
  28. for (i=0; i<1024*4096; ++i)
  29. p[i] = 0;
  30. sc_print();
  31. if ( p )
  32. free( p );
  33. return 0;
  34. }