• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 297,  comments - 15,  trackbacks - 0
                  對(duì)于多線程應(yīng)用程序,如果能夠給每個(gè)線程命名,那么調(diào)試起來(lái)的便利是不言而喻的。
                  可以用prctl給進(jìn)程內(nèi)其它線程命名的接口,測(cè)試代碼如下:


            #include <stdio.h>
            #include <pthread.h>
            #include <sys/prctl.h>
            #include <unistd.h>

            void* pFunc(void *arg)
            {
                char name[32];
                prctl(PR_SET_NAME, (unsigned long)"xx");
                prctl(PR_GET_NAME, (unsigned long)name);
                printf("%s\n", name);
                while (1)
                    sleep(1);
            }

            int main(void)
            {
                pthread_t tid;
                pthread_create(&tid, NULL, pFunc, NULL);
                pthread_join(tid, NULL);
             
                return 0;
            }


            makefile:
            .PHONY: all
            all: thread

            thread : thread.cpp
                g++ -ggdb -Wall -lpthread -o thread thread.cpp

            clean:
                rm -f thread *.swp

                  看thread進(jìn)程,但是還看不到線程信息
            beauty@linux-gznp:~/code/test> ps aux | grep thread | grep beauty | grep -v grep
            beauty    8364  0.0  0.3  10872   904 pts/2    Sl   03:24   0:00 ./thread

                  再給ps加幾個(gè)參數(shù)就ok了。
            ps -L -p `ps aux | grep thread | grep $USER | grep -v grep | awk '{print $2}'`
              PID   LWP TTY          TIME CMD
             8364  8364 pts/2    00:00:00 thread
             8364  8365 pts/2    00:00:00 xx
                 這里的-L,也可以使用-T,只是打出的詳細(xì)信息有點(diǎn)兒不同。具體如下:
            -L              Show threads, possibly with LWP and NLWP columns

            -T              Show threads, possibly with SPID column







            posted on 2009-11-08 22:16 chatler 閱讀(5032) 評(píng)論(2)  編輯 收藏 引用 所屬分類(lèi): Linux_Coding

            FeedBack:
            # re: 用prctl給線程命名
            2012-05-27 21:52 | dhao123@sina.com
            請(qǐng)問(wèn)大俠: 用top命令的時(shí)候可以顯示修改后的線程名么?如何做呢?  回復(fù)  更多評(píng)論
              
            # re: 用prctl給線程命名
            2012-06-02 11:34 | none
            用top -H 可以的。
            [root@linux-x86 test]# top -H
            PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
            27036 root 25 0 16184 524 420 R 52.7 0.1 0:11.45 xx
            26832 root 15 0 90116 3644 2896 R 5.3 0.5 0:00.44 sshd
            1 root 15 0 10348 744 624 S 0.0 0.1 0:00.75 init
            2 root RT -5 0 0 0 S 0.0 0.0 0:01.43 migration/0
              回復(fù)  更多評(píng)論
              
            <2008年9月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            常用鏈接

            留言簿(10)

            隨筆分類(lèi)(307)

            隨筆檔案(297)

            algorithm

            Books_Free_Online

            C++

            database

            Linux

            Linux shell

            linux socket

            misce

            • cloudward
            • 感覺(jué)這個(gè)博客還是不錯(cuò),雖然做的東西和我不大相關(guān),覺(jué)得看看還是有好處的

            network

            OSS

            • Google Android
            • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
            • os161 file list

            overall

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久精品中文闷骚内射| 香蕉久久夜色精品国产2020| 久久久一本精品99久久精品88| 欧美久久久久久精选9999| 狠狠色丁香久久综合五月| 久久午夜无码鲁丝片| 国内高清久久久久久| 中文字幕久久久久人妻| 欧美日韩久久中文字幕| 无码任你躁久久久久久老妇App| 九九久久精品无码专区| 国产毛片久久久久久国产毛片| 色综合久久综精品| 88久久精品无码一区二区毛片| 国产精品久久久久久久久| 国内精品久久久人妻中文字幕 | 久久久久免费视频| 久久黄视频| 久久影视综合亚洲| 天堂无码久久综合东京热| 国产精品久久婷婷六月丁香| 中文字幕乱码久久午夜| 日本人妻丰满熟妇久久久久久| 久久久国产精品亚洲一区| 久久久久久无码Av成人影院| 国产精品久久自在自线观看| aaa级精品久久久国产片| 99久久人妻无码精品系列 | 欧美亚洲另类久久综合| 久久99免费视频| 国产精品成人99久久久久91gav| 99久久伊人精品综合观看| 亚洲国产成人久久笫一页| 久久精品国产亚洲AV忘忧草18 | 久久久WWW成人| 思思久久99热只有频精品66| 99久久国产宗和精品1上映| 成人国内精品久久久久一区| 国产精品嫩草影院久久| 亚洲伊人久久成综合人影院| 欧美日韩久久中文字幕|