m0_64942419 2022-05-30 09:46 采纳率: 50%
浏览 68
已结题

Linux mincore

有人知道这个Linux 系统的mincore怎么使用吗?可以举个例子吗?想用来判断一段信息是不是在内存里面

img

  • 写回答

1条回答 默认 最新

  • 赵4老师 2022-05-30 13:47
    关注

    MINCORE(2) Linux Programmer's Manual MINCORE(2)

    NAME
    mincore - determine whether pages are resident in memory

    SYNOPSIS
    #include <unistd.h>
    #include <sys/mman.h>

       int mincore(void *addr, size_t length, unsigned char *vec);
    

    Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       mincore():
           Since glibc 2.19:
               _DEFAULT_SOURCE
           Glibc 2.19 and earlier:
               _BSD_SOURCE || _SVID_SOURCE
    

    DESCRIPTION
    mincore() returns a vector that indicates whether pages of the calling process's vir‐
    tual memory are resident in core (RAM), and so will not cause a disk access (page
    fault) if referenced. The kernel returns residency information about the pages start‐
    ing at the address addr, and continuing for length bytes.

       The addr argument must be a multiple of the system page  size.   The  length  argument
       need  not  be a multiple of the page size, but since residency information is returned
       for whole pages, length is effectively rounded up to the next  multiple  of  the  page
       size.  One may obtain the page size (PAGE_SIZE) using sysconf(_SC_PAGESIZE).
    
       The  vec  argument  must  point to an array containing at least (length+PAGE_SIZE-1) /
       PAGE_SIZE bytes.  On return, the least significant bit of each byte will be set if the
       corresponding page is currently resident in memory, and be clear otherwise.  (The set‐
       tings of the other bits in each byte are undefined; these bits are reserved for possi‐
       ble  later  use.)  Of course the information returned in vec is only a snapshot: pages
       that are not locked in memory can come and go at any moment, and the contents  of  vec
       may already be stale by the time this call returns.
    

    RETURN VALUE
    On success, mincore() returns zero. On error, -1 is returned, and errno is set appro‐
    priately.

    ERRORS
    EAGAIN kernel is temporarily out of resources.

       EFAULT vec points to an invalid address.
    
       EINVAL addr is not a multiple of the page size.
    
       ENOMEM length is greater than (TASK_SIZE - addr).  (This could  occur  if  a  negative
              value  is specified for length, since that value will be interpreted as a large
              unsigned integer.)  In Linux 2.6.11 and earlier, the error EINVAL was  returned
              for this condition.
    
       ENOMEM addr to addr + length contained unmapped memory.
    

    VERSIONS
    Available since Linux 2.3.99pre1 and glibc 2.2.

    CONFORMING TO
    mincore() is not specified in POSIX.1, and it is not available on all UNIX implementa‐
    tions.

    BUGS
    Before kernel 2.6.21, mincore() did not return correct information for MAP_PRIVATE
    mappings, or for nonlinear mappings (established using remap_file_pages(2)).

    SEE ALSO
    fincore(1), madvise(2), mlock(2), mmap(2), posix_fadvise(2), posix_madvise(3)

    COLOPHON
    This page is part of release 4.15 of the Linux man-pages project. A description of
    the project, information about reporting bugs, and the latest version of this page,
    can be found at https://www.kernel.org/doc/man-pages/.

    Linux 2017-09-15 MINCORE(2)

    以下为百度翻译自动翻译内容:
    MINCORE(2)Linux程序员手册MINCORE(2)
    名称
    mincore-确定页是否驻留在内存中
    简介
    #包括<unistd。h>
    #包括<系统/手动。h>
    int mincore(voidaddr,size\t length,unsigned charvec);
    glibc的功能测试宏要求(参见Feature\u Test\u macros(7)):
    mincore():
    自glibc 2.19以来:
    _默认\u源
    Glibc 2.19及更早版本:
    _BSD\U源| | \U SVID\U源
    说明:
    mincore()返回一个向量,该向量指示调用进程的vir
    实际内存驻留在内核(RAM)中,因此不会导致磁盘访问(第页
    故障),如果参考。内核返回有关页面开始的驻留信息‐
    在地址addr处执行ing,并继续执行长度字节。
    addr参数必须是系统页面大小的倍数。长度参数
    不需要是页面大小的倍数,但由于返回了派驻信息
    对于整个页面,长度有效地向上舍入到页面的下一个倍数
    大小可以使用sysconf(\u SC\u PAGESIZE)获取页面大小(page\u size)。
    vec参数必须指向至少包含(长度+PAGE\u SIZE-1)的数组/
    PAGE\u大小字节。返回时,如果
    相应的页当前驻留在内存中,否则请清除。(集合‐
    每个字节中其他位的类型未定义;这些位是为possi‐保留的
    ble以后使用。)当然,vec中返回的信息只是一个快照:页面
    未锁定在内存中的内容可以随时进出,vec的内容
    此调用返回时可能已过时。
    返回值
    成功时,mincore()返回零。出现错误时,返回-1,并将errno设置为适当
    是的。
    错误
    EAGAIN内核暂时资源不足。
    EFAULT vec指向无效地址。
    EINVAL addr不是页面大小的倍数。
    ENOMEM长度大于(TASK\u SIZE-addr)。(如果出现负
    值是为长度指定的,因为该值将被解释为大
    无符号整数。)在Linux 2.6.11及更早版本中,返回了错误EINVAL
    对于这种情况。
    ENOMEM addr to addr+包含未映射内存的长度。
    版本
    自Linux 2.3.99pre1和glibc 2.2起提供。
    符合
    POSIX中未指定mincore()。1,并且并非在所有UNIX实现上都可用
    选项。
    错误
    在内核2.6.21之前,mincore()没有为MAP\u PRIVATE返回正确的信息
    映射,或非线性映射(使用remap\u file\u pages(2)建立)。
    另请参见
    fincore(1)、madvise(2)、mlock(2)、mmap(2)、posix\u fadvise(2)、posix\u madvise(3)
    树脂
    此页面是Linux手册页项目4.15版的一部分。描述
    项目、有关报告错误的信息以及此页面的最新版本,
    可在以下位置找到https://www.kernel.org/doc/man-pages/.
    Linux 2017-09-15 MINCORE(2)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 6月7日
  • 已采纳回答 5月30日
  • 赞助了问题酬金5元 5月30日
  • 创建了问题 5月30日

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路