创建若干线程:
while(1)
{
fd_set()
select() //由于超时时间设置为0,会直接返回
proc()
nanosleep(&t, NULL) //t == 100us
}
top 已经到700多了
Tasks: 404 total, 1 running, 403 sleeping, 0 stopped, 0 zombie
Cpu0 : 41.1%us, 32.1%sy, 0.0%ni, 21.5%id, 4.1%wa, 0.0%hi, 1.1%si, 0.0%st
Cpu1 : 35.8%us, 28.6%sy, 0.0%ni, 25.2%id, 3.2%wa, 0.0%hi, 7.2%si, 0.0%st
Cpu2 : 36.0%us, 27.4%sy, 0.0%ni, 32.0%id, 4.3%wa, 0.0%hi, 0.4%si, 0.0%st
Cpu3 : 36.7%us, 25.7%sy, 0.0%ni, 33.6%id, 3.6%wa, 0.0%hi, 0.4%si, 0.0%st
Cpu4 : 40.3%us, 30.2%sy, 0.0%ni, 25.1%id, 3.2%wa, 0.0%hi, 1.1%si, 0.0%st
Cpu5 : 36.6%us, 27.8%sy, 0.0%ni, 31.1%id, 2.4%wa, 0.0%hi, 2.2%si, 0.0%st
Cpu6 : 34.4%us, 23.5%sy, 0.0%ni, 32.8%id, 2.2%wa, 0.0%hi, 7.1%si, 0.0%st
Cpu7 : 35.2%us, 24.9%sy, 0.0%ni, 36.7%id, 2.9%wa, 0.0%hi, 0.4%si, 0.0%st
Mem: 32873536k total, 30442736k used, 2430800k free, 120744k buffers
Swap: 8191992k total, 14336k used, 8177656k free, 27738484k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
13436 root 20 0 1444m 264m 1944 S 753.3 0.8 67:20.94 thr
gdb大部分停在
Thread 0x7fa565afd710 (LWP 13449) 0x0000003f2820eced in nanosleep () from /lib64/libpthread.so.0
怎么可以使cpu降下去?谢谢 |