V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
pinkman
V2EX  ›  问与答

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

  •  
  •   pinkman · 2015-03-10 18:49:28 +08:00 · 2808 次点击
    这是一个创建于 3338 天前的主题,其中的信息可能已经有所发展或是发生改变。
    刚换了个风扇,想让cpu占用率升起来好看看新风扇转不...
    18 条回复    2015-03-11 12:43:47 +08:00
    spoony
        1
    spoony  
       2015-03-10 18:53:12 +08:00
    挽尊,Chrome开起来去优酷播一段720P就行。
    pinkman
        2
    pinkman  
    OP
       2015-03-10 18:53:45 +08:00
    @spoony 现在没有网,那待会儿回家去试试 :)
    tabris17
        3
    tabris17  
       2015-03-10 18:56:23 +08:00
    下个super pi啊
    20150517
        4
    20150517  
       2015-03-10 19:02:11 +08:00
    开flash.......
    20150517
        5
    20150517  
       2015-03-10 19:02:47 +08:00
    哦对了,是在被窝里看1080P的flash,那个飙的叫爽啊,冬天直接可以当电热毯用了
    ChanneW
        6
    ChanneW  
       2015-03-10 19:08:34 +08:00
    Python 要开对应核数的进程才能跑到 100%
    zhjits
        7
    zhjits  
       2015-03-10 20:41:02 +08:00
    smcFanControl 装好往 5000 转拉就行
    pinkman
        8
    pinkman  
    OP
       2015-03-10 20:55:04 +08:00   ❤️ 1
    @zhjits 装好了,啦到了6500还是没有转呢?显示的温度是37
    binux
        9
    binux  
       2015-03-10 21:01:15 +08:00   ❤️ 1
    cat /dev/urandom > /dev/null
    pinkman
        10
    pinkman  
    OP
       2015-03-10 21:02:28 +08:00
    估计我这风扇是没有装好,现在用chrome开了4个超清视频爱奇艺、搜狐、youku、土豆,smcfancontrol显示温度71度,activity monitor中光是chrome helper的cpu占用率就是147%(这数怎么来的?会超过100%?),但风扇还是没有转...
    uniquecolesmith
        11
    uniquecolesmith  
       2015-03-10 21:03:55 +08:00
    是用于给妹纸取暖?哈哈
    pinkman
        12
    pinkman  
    OP
       2015-03-10 21:04:43 +08:00
    @binux 这段代码干什么的,果真有效,但也证明了风扇没有装好...
    zhjits
        13
    zhjits  
       2015-03-10 21:06:08 +08:00
    @pinkman 那软件在有些机型(比如我的)上有问题,不能拉到 6500,5000 左右才行……
    bellchu
        14
    bellchu  
       2015-03-10 21:13:16 +08:00 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  
       2015-03-10 21:15:45 +08:00
    @pinkman
    Geekbench 一下就好了
    gaocegege
        16
    gaocegege  
       2015-03-10 22:38:52 +08:00
    #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
    GeekGao
        17
    GeekGao  
       2015-03-11 12:43:15 +08:00
    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()
    GeekGao
        18
    GeekGao  
       2015-03-11 12:43:47 +08:00
    shit ,缩进呢。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5240 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:49 · PVG 16:49 · LAX 01:49 · JFK 04:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.