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;
    }

  • 相关阅读:
    SQL Server控制语句
    MATLAB中取整函数(fix, floor, ceil, round)的使用
    MATLAB程序设计
    Thinking In Java<<Java编程思想>>
    Boost::bimap
    MySQL学习随笔1
    Boost 1_42_0在windows下的编译及其设置
    MySQL执行mysql脚本及其脚本编写
    Pygame介绍
    Erlang
  • 原文地址:https://www.cnblogs.com/otakus/p/13222486.html
Copyright © 2011-2022 走看看