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

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 3878 | 回復(fù): 5
打印 上一主題 下一主題

無(wú)法打印出線程號(hào),這是為什么呢? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-10-29 15:34 |只看該作者 |倒序?yàn)g覽
程序a.c如下
  1. #include <pthread.h>
  2. #include <stdio.h>
  3. #include <unistd.h>

  4. void *myThread(void *arg)
  5. {
  6.    sleep(1000);
  7.    return 0;
  8. }
  9. main()
  10. {
  11.    int ret;
  12.    char tmpstr[20];

  13.    pthread_t mythread=0;
  14.    ret = pthread_create( &mythread, NULL, myThread, NULL );
  15.    printf("tid=%lu\n",mythread);
  16.    ret = pthread_create( &mythread, NULL, myThread, NULL );
  17.    printf("tid=%lu\n",mythread);
  18.    ret = pthread_create( &mythread, NULL, myThread, NULL );
  19.    printf("tid=%lu\n",mythread);
  20.    ret = pthread_create( &mythread, NULL, myThread, NULL );
  21.    printf("tid=%lu\n",mythread);

  22.    printf("tid=%lu\n",mythread);



  23.    sleep(1000);
  24. }
復(fù)制代碼
編譯:
gcc  a.c -lpthread生成a.out
執(zhí)行a.out輸出
tid=3086244752
tid=3075750800
tid=3065260944
tid=3054771088
tid=3044281232
而通過(guò)執(zhí)行pstree 命令
$ pstree -p 17384
其中17384是進(jìn)程號(hào)
a.out(17384)-+-{a.out}(17385)
            |-{a.out}(17386)
            |-{a.out}(17387)
            |-{a.out}(1738
            `-{a.out}(17389)
為什么打印的不對(duì)呢?
用printf("%u",tid)也相同
用printf("%d",tid)竟然是負(fù)數(shù),當(dāng)然也不對(duì)。
該如何輸出呢?

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2010-10-29 16:49 |只看該作者
pthread_self()

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2010-10-29 16:54 |只看該作者
getppid

論壇徽章:
1
CU十二周年紀(jì)念徽章
日期:2013-10-24 15:41:34
4 [報(bào)告]
發(fā)表于 2010-10-29 16:55 |只看該作者
LZ這樣輸出應(yīng)該是對(duì)的,在linux中pthread_t應(yīng)該是個(gè)無(wú)符號(hào)整數(shù)。

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2010-10-29 17:13 |只看該作者
回復(fù) 4# ecjtubaowp


    知音!可打印咋就不對(duì)呢,在AIX 6就是對(duì)!

論壇徽章:
1
CU十二周年紀(jì)念徽章
日期:2013-10-24 15:41:34
6 [報(bào)告]
發(fā)表于 2010-10-29 17:31 |只看該作者
回復(fù) 5# demaple


    你用pstree打印的我就不清楚了,你看看/proc/pid/task,這個(gè)目錄是該進(jìn)程的所有線程,包含pid主線程
您需要登錄后才可以回帖 登錄 | 注冊(cè)

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

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP