zoukankan      html  css  js  c++  java
  • OSTEP第十三章测试题

    2. Now, run free, perhaps using some of the arguments that might be useful (e.g., -m, to display memory totals in megabytes). 
    How much memory is in your system? 
    How much is free? Do these numbers match your intuition?
    siuwhat@siuwhat-PC:~/Desktop/HW-Lottery$ free -m
                  total        used        free      shared  buff/cache   available
    Mem:           1970        1305         123          44         541         461
    Swap:          4095          70        4025
    3. Next, create a little program that uses a certain amount of memory, called memory-user.c. This program should take one command-line argument: the number of megabytes of memory it will use. When run, it should allocate an array, and constantly stream through the array, touching each entry. The program should do this indefinitely, or, perhaps, for a certain amount of time also specified at the command line.
    8. Finally, let’s run pmap on your your memory-user program, with different amounts of used memory. What do you see here? Does the output from pmap match your expectations?
    #include <iostream>
    #include<unistd.h>
    using namespace std;
    int main(int argc, char *argv[]) {
        size_t mem=atoi(argv[1]);
        const size_t num=mem*1024*1024/sizeof(int);
        int array[num];
        while(true){
        for(int i=0;i<num;++i)
            {array[i]=i;
                cout<<getpid()<<"  "<<i<<endl;}
        }
        return 0;
    }

  • 相关阅读:
    应用程序跳转
    百度地图集成
    导航 -MapKit
    导航
    定位
    ApexSql Log使用体会
    Oracle学习 第16天
    上来冒个泡吧
    Oracle学习 实战心得总结
    好久没上来冒个泡了,整整一个半月
  • 原文地址:https://www.cnblogs.com/otakus/p/13222486.html
Copyright © 2011-2022 走看看