pinkman
V2EX  ›  问与答

求一段 Python 一代让 os x cpu 占用率飙升起来

  •  
  •   pinkman · Mar 10, 2015 · 3425 views
    This topic created in 4124 days ago, the information mentioned may be changed or developed.
    刚换了个风扇,想让cpu占用率升起来好看看新风扇转不...
    18 replies    2015-03-11 12:43:47 +08:00
    spoony
        1
    spoony  
       Mar 10, 2015
    挽尊,Chrome开起来去优酷播一段720P就行。
    pinkman
        2
    pinkman  
    OP
       Mar 10, 2015
    @spoony 现在没有网,那待会儿回家去试试 :)
    tabris17
        3
    tabris17  
       Mar 10, 2015
    下个super pi啊
    20150517
        4
    20150517  
       Mar 10, 2015
    开flash.......
    20150517
        5
    20150517  
       Mar 10, 2015
    哦对了,是在被窝里看1080P的flash,那个飙的叫爽啊,冬天直接可以当电热毯用了
    ChanneW
        6
    ChanneW  
       Mar 10, 2015
    Python 要开对应核数的进程才能跑到 100%
    zhjits
        7
    zhjits  
       Mar 10, 2015
    smcFanControl 装好往 5000 转拉就行
    pinkman
        8
    pinkman  
    OP
       Mar 10, 2015   ❤️ 1
    @zhjits 装好了,啦到了6500还是没有转呢?显示的温度是37
    binux
        9
    binux  
       Mar 10, 2015   ❤️ 1
    cat /dev/urandom > /dev/null
    pinkman
        10
    pinkman  
    OP
       Mar 10, 2015
    估计我这风扇是没有装好,现在用chrome开了4个超清视频爱奇艺、搜狐、youku、土豆,smcfancontrol显示温度71度,activity monitor中光是chrome helper的cpu占用率就是147%(这数怎么来的?会超过100%?),但风扇还是没有转...
    uniquecolesmith
        11
    uniquecolesmith  
       Mar 10, 2015
    是用于给妹纸取暖?哈哈
    pinkman
        12
    pinkman  
    OP
       Mar 10, 2015
    @binux 这段代码干什么的,果真有效,但也证明了风扇没有装好...
    zhjits
        13
    zhjits  
       Mar 10, 2015
    @pinkman 那软件在有些机型(比如我的)上有问题,不能拉到 6500,5000 左右才行……
    bellchu
        14
    bellchu  
       Mar 10, 2015 via iPhone
    Popen.wait()
    Wait for child process to terminate. Set and return returncode attribute.

    Warning This will deadlock when using stdout=PIPE and/or stderr=PIPE and the child process generates enough output to a pipe such that it blocks waiting for the OS pipe buffer to accept more data. Use communicate() to avoid that.
    ynyounuo
        15
    ynyounuo  
       Mar 10, 2015
    @pinkman
    Geekbench 一下就好了
    gaocegege
        16
    gaocegege  
       Mar 10, 2015
    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>

    #define NUM_OF_CORES 8
    #define MAX_PRIME 100000

    void do_primes()
    {
    unsigned long i, num, primes = 0;
    for (num = 1; num <= MAX_PRIME; ++num) {
    for (i = 2; (i <= num) && (num % i != 0); ++i);
    if (i == num)
    ++primes;
    }
    printf("Calculated %d primes.\n", primes);
    }

    int main(int argc, char ** argv)
    {
    time_t start, end;
    time_t run_time;
    unsigned long i;
    pid_t pids[NUM_OF_CORES];

    /* start of test */
    start = time(NULL);
    for (i = 0; i < NUM_OF_CORES; ++i) {
    if (!(pids[i] = fork())) {
    do_primes();
    exit(0);
    }
    if (pids[i] < 0) {
    perror("Fork");
    exit(1);
    }
    }
    for (i = 0; i < NUM_OF_CORES; ++i) {
    waitpid(pids[i], NULL, 0);
    }
    end = time(NULL);
    run_time = (end - start);
    printf("This machine calculated all prime numbers under %d %d times "
    "in %d seconds\n", MAX_PRIME, NUM_OF_CORES, run_time);
    return 0;
    }


    From http://stackoverflow.com/a/9244508/4358533
    R4rvZ6agNVWr56V0
        17
    R4rvZ6agNVWr56V0  
       Mar 11, 2015
    import multiprocessing

    def fuck_cpus():
    while True:
    print 'Fucking...'

    CPU_CORE = 4
    for i in xrange(CPU_CORE):
    multiprocessing.Process(target=fuck_cpus, args=()).start()
    R4rvZ6agNVWr56V0
        18
    R4rvZ6agNVWr56V0  
       Mar 11, 2015
    shit ,缩进呢。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3129 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 13:08 · PVG 21:08 · LAX 06:08 · JFK 09:08
    ♥ Do have faith in what you're doing.