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

2015-03-10 18:49:28 +08:00
 pinkman
刚换了个风扇,想让cpu占用率升起来好看看新风扇转不...
2903 次点击
所在节点    问与答
18 条回复
spoony
2015-03-10 18:53:12 +08:00
挽尊,Chrome开起来去优酷播一段720P就行。
pinkman
2015-03-10 18:53:45 +08:00
@spoony 现在没有网,那待会儿回家去试试 :)
tabris17
2015-03-10 18:56:23 +08:00
下个super pi啊
20150517
2015-03-10 19:02:11 +08:00
开flash.......
20150517
2015-03-10 19:02:47 +08:00
哦对了,是在被窝里看1080P的flash,那个飙的叫爽啊,冬天直接可以当电热毯用了
ChanneW
2015-03-10 19:08:34 +08:00
Python 要开对应核数的进程才能跑到 100%
zhjits
2015-03-10 20:41:02 +08:00
smcFanControl 装好往 5000 转拉就行
pinkman
2015-03-10 20:55:04 +08:00
@zhjits 装好了,啦到了6500还是没有转呢?显示的温度是37
binux
2015-03-10 21:01:15 +08:00
cat /dev/urandom > /dev/null
pinkman
2015-03-10 21:02:28 +08:00
估计我这风扇是没有装好,现在用chrome开了4个超清视频爱奇艺、搜狐、youku、土豆,smcfancontrol显示温度71度,activity monitor中光是chrome helper的cpu占用率就是147%(这数怎么来的?会超过100%?),但风扇还是没有转...
uniquecolesmith
2015-03-10 21:03:55 +08:00
是用于给妹纸取暖?哈哈
pinkman
2015-03-10 21:04:43 +08:00
@binux 这段代码干什么的,果真有效,但也证明了风扇没有装好...
zhjits
2015-03-10 21:06:08 +08:00
@pinkman 那软件在有些机型(比如我的)上有问题,不能拉到 6500,5000 左右才行……
bellchu
2015-03-10 21:13:16 +08:00
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
2015-03-10 21:15:45 +08:00
@pinkman
Geekbench 一下就好了
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
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
2015-03-11 12:43:47 +08:00
shit ,缩进呢。。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/175890

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX