Linux 获取内存页大小

如何查看Linux系统的内存页大小:
1. getconf PAGESIZE/PAGE_SIZE  返回值单位为Bytes

点击(此处)折叠或打开

  1. [root@localhost nginx-1.8.0]# getconf PAGESIZE
  2. 4096
  3. [root@localhost nginx-1.8.0]# getconf PAGE_SIZE
  4. 4096
2. 通过c函数获取
  #include 
   int getpagesize(void);返回值单位为Bytes


点击(此处)折叠或打开

  1. The function getpagesize() returns the number of bytes in a page, where a "page" is the thing used where it says in the description of mmap(2) that files are mapped in page-sized units.

  2.        The size of the kind of pages that mmap() uses, is found using

  3.               #include <unistd.h>
  4.               long sz = sysconf(_SC_PAGESIZE);

  5.        (where some systems also allow the synonym _SC_PAGE_SIZE for _SC_PAGESIZE), or

  6.               #include <unistd.h>
  7.               int sz = getpagesize()
pagesize.c

点击(此处)折叠或打开

  1. [root@localhost test]# more pagesize.c
  2. #include <unistd.h>
  3. #include <stdio.h>
  4. int main(int argc, char *argv[])
  5. {
  6.     printf("linux page size is %d bytes\n",getpagesize());
  7.     return 0;
  8. }
编译运行:

点击(此处)折叠或打开

  1. [root@localhost test]# gcc -g pagesize.-o pagesize -Wall
  2. [root@localhost test]# ./pagesize 
  3. linux page size is 4096 bytes

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值