当前位置:早雪网网络学院编程文档C/C++ → Unix编程/应用问答中文版 ---4.系统资源相关问题

Unix编程/应用问答中文版 ---4.系统资源相关问题

减小字体 增大字体 作者:不详  来源:supcode.com收集整理  发布时间:2005-7-22 19:40:35
clude <unistd.h> 

int main ( int argc, char * argv[] ) 

    int           fd = open( THEMEM, O_RDONLY ); 
    char          c; 
    unsigned long pos, mapstart = 0; 
    int           totmb = 0; 

    if ( fd == -1 ) 
    { 
        perror( THEMEM ); 
        exit( 1 ); 
    } 
    for ( pos = 0; pos < MAXMEM; pos += MEGABYTE ) 
    { 
        if (lseek( fd, pos, 0 ) == -1 ) 
        { 
            perror( "lseek" ); 
            exit( 1 ); 
        } 
        if ( read( fd, &c, 1 ) == -1 ) 
        { 
            int size = ( pos - mapstart ) / MEGABYTE; 

            if ( size != 0 ) 
            { 
                printf( "found %3d MB starting at 0x%p\n", size, ( void * )mapst 
art ); 
                totmb += size; 
            } 
            mapstart = pos + MEGABYTE;  /* start of next possible mapping */ 
        } 
    } 
    printf( "Total memory size: %d MB\n", totmb ); 
    exit( 0 ); 

-------------------------------------------------------------------------- 

由于需要读访问/dev/mem,普通用户用户无法使用该程序。 

上一页  [1] [2] 

[数据载入中...] [返回上一页] [打 印]