亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 6779 | 回復(fù): 3
打印 上一主題 下一主題

[C] [已解決]多核系統(tǒng)中怎么查看進程的某個線程被分配到哪個cpu上? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2010-04-02 10:33 |只看該作者 |倒序瀏覽
本帖最后由 wwdwwd 于 2010-04-02 11:54 編輯

[求教]多核系統(tǒng)中怎么查看進程的某個線程被分配到哪個cpu上?

論壇徽章:
0
2 [報告]
發(fā)表于 2010-04-02 10:51 |只看該作者

  1.        #define _GNU_SOURCE
  2.        #include <pthread.h>

  3.        int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize,
  4.                                   const cpu_set_t *cpuset);
  5.        int pthread_getaffinity_np(pthread_t thread, size_t cpusetsize,
  6.                                   cpu_set_t *cpuset);
復(fù)制代碼

論壇徽章:
0
3 [報告]
發(fā)表于 2010-04-02 11:54 |只看該作者
問題解決了,linux下用sched_getcpu即可,不過要求內(nèi)核高于2.6.19,glibc高于2.6。另外,cpu的親和性只是說可以把某個線程綁定到某個cpu上,而不能獲取當前的線程正被綁定到某個cpu上。

http://www.kernel.org/doc/man-pa ... sched_getcpu.3.html
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<sys/types.h>
  4. #include<sys/sysinfo.h>
  5. #include<unistd.h>

  6. #define _GNU_SOURCE
  7. #include <sched.h>


  8. #include<ctype.h>
  9. #include<string.h>
  10. #include<pthread.h>


  11. void get_process() {
  12.                 printf("cpu is %d\n",sched_getcpu());
  13. }

  14. void *test(void *arg) {
  15.        long long i;
  16.       get_process();
  17.         return (void*)0;

  18. }
  19. int main(int argc, char* argv[])
  20. {
  21.                 pthread_t tid;
  22.               pthread_create(&tid,NULL,test,NULL);
  23.               pthread_create(&tid,NULL,test,NULL);
  24.               pthread_create(&tid,NULL,test,NULL);
  25.               pthread_create(&tid,NULL,test,NULL);
  26.               pthread_create(&tid,NULL,test,NULL);
  27.                 get_process();
  28.                 return 0;
  29. }
復(fù)制代碼

論壇徽章:
0
4 [報告]
發(fā)表于 2010-04-02 12:17 |只看該作者
學(xué)習(xí)學(xué)習(xí),咱就用過雙核
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP