• <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
                  對于多線程應用程序,如果能夠給每個線程命名,那么調試起來的便利是不言而喻的。
                  可以用prctl給進程內其它線程命名的接口,測試代碼如下:


            #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進程,但是還看不到線程信息
            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加幾個參數就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,只是打出的詳細信息有點兒不同。具體如下:
            -L              Show threads, possibly with LWP and NLWP columns

            -T              Show threads, possibly with SPID column







            posted on 2009-11-08 22:16 chatler 閱讀(5049) 評論(2)  編輯 收藏 引用 所屬分類: Linux_Coding

            FeedBack:
            # re: 用prctl給線程命名
            2012-05-27 21:52 | dhao123@sina.com
            請問大俠: 用top命令的時候可以顯示修改后的線程名么?如何做呢?  回復  更多評論
              
            # 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
              回復  更多評論
              
            <2009年11月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            常用鏈接

            留言簿(10)

            隨筆分類(307)

            隨筆檔案(297)

            algorithm

            Books_Free_Online

            C++

            database

            Linux

            Linux shell

            linux socket

            misce

            • cloudward
            • 感覺這個博客還是不錯,雖然做的東西和我不大相關,覺得看看還是有好處的

            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

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久97久久97精品免视看| 日本精品久久久中文字幕| 伊人精品久久久久7777| 亚洲欧美成人综合久久久| 亚洲中文字幕久久精品无码喷水 | 品成人欧美大片久久国产欧美...| 办公室久久精品| 亚洲午夜久久久久久噜噜噜| 国产激情久久久久影院| 久久精品国产亚洲av影院| 亚洲精品无码久久久| 麻豆久久| 久久综合久久综合亚洲| 久久久久亚洲精品无码网址| 97精品伊人久久大香线蕉app | 五月丁香综合激情六月久久| 国产精品久久新婚兰兰| 久久综合亚洲色HEZYO国产| 久久精品中文字幕第23页| 久久亚洲国产精品五月天婷| 久久99精品国产麻豆婷婷| 一级做a爰片久久毛片人呢| 97久久国产综合精品女不卡| 久久人人爽人人爽人人片av麻烦| 久久只有这精品99| 99久久中文字幕| 久久性精品| 久久噜噜电影你懂的| 久久久午夜精品| 久久精品国产精品亚洲毛片| 国产精品美女久久久久久2018| 久久九九全国免费| 亚洲午夜久久久久妓女影院| 99久久精品毛片免费播放| 狠狠色丁香婷婷久久综合五月 | 久久成人精品视频| 欧美黑人激情性久久| 怡红院日本一道日本久久 | 无码精品久久久久久人妻中字| 99久久精品免费看国产一区二区三区 | 亚洲乱码中文字幕久久孕妇黑人|