• <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>

            lxyfirst

            C++博客 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
              33 Posts :: 3 Stories :: 27 Comments :: 0 Trackbacks
            在linux下開發(fā)的多線程系統(tǒng)中,每個(gè)線程的調(diào)試和監(jiān)控一直比較麻煩,無(wú)法精準(zhǔn)定位,現(xiàn)在有了解決辦法了。
            linux下的prctl庫(kù)自kernel 2.6.9后支持PR_SET_NAME選項(xiàng),用于設(shè)置進(jìn)程名字,linux的進(jìn)程一般使用lwp,所以這個(gè)函數(shù)可以設(shè)置線程名字。
            api定義如下
            int prctl( int option,unsigned long arg2,unsigned long arg3,unsigned long arg4,unsigned long arg5); 

            PR_SET_NAME (since Linux 
            2.6.9
            Set the process name 
            for the calling process, using the value in the location pointed to by (char *) arg2. The name can be up to 16 bytes long, and should be null-terminated if it contains fewer bytes.

            PR_GET_NAME (since Linux 
            2.6.11
            Return the process name 
            for the calling process, in the buffer pointed to by (char *) arg2. The buffer should allow space for up to 16 bytes; the returned string will be null-terminated if it is shorter than that.


            簡(jiǎn)單實(shí)現(xiàn)代碼:

            int set_thread_title(const char* fmt, )
            {
                
            char title [16={0};
                va_list ap;
                va_start(ap, fmt);
                vsnprintf (title, 
            sizeof (title) , fmt, ap);
                va_end (ap);

               
            return prctl(PR_SET_NAME,title) ;

            }

            現(xiàn)在能夠?yàn)榫€程設(shè)置名字了,那么如何看到呢
            ps -eL -o pid,user,lwp,comm
            top 
            -



            posted on 2011-03-07 16:11 star 閱讀(7814) 評(píng)論(2)  編輯 收藏 引用

            Feedback

            # re: linux下設(shè)置線程的名字 2012-05-28 11:24 dhao123@sina.com
            請(qǐng)問(wèn)大俠: top -H 這個(gè)命令可以顯示出來(lái) 之前設(shè)置好的thread 名字么?
            這個(gè)選項(xiàng)字 -H 表示什么? 沒有man到啊

            就是說(shuō)通過(guò)prctl () 這個(gè)接口設(shè)置thread 名字后,如何驗(yàn)證???
            用top命令 或者pgrep 之類的
              回復(fù)  更多評(píng)論
              

            # re: linux下設(shè)置線程的名字 2014-10-31 14:57 拉力
            @dhao123@sina.com
            查看 cd/proc/pid/task/tid/status 文件的第一個(gè)名字;
            pid :進(jìn)程號(hào)
            tid : 線程號(hào)  回復(fù)  更多評(píng)論
              


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            模特私拍国产精品久久| 亚洲国产精品久久久久婷婷软件| 久久久久久久久久免免费精品| 精品国产91久久久久久久a| 久久久久97国产精华液好用吗| 九九精品久久久久久噜噜| 日韩AV无码久久一区二区| 久久国产精品免费| 亚洲中文字幕无码久久精品1| 7国产欧美日韩综合天堂中文久久久久| 狠狠综合久久综合中文88 | 国产一区二区久久久| 久久国产精品无码HDAV| 无码人妻久久一区二区三区蜜桃 | 国产精品久久免费| 久久亚洲AV成人无码软件| 国产精品伊人久久伊人电影| 国产精品久久久久久久app| 精品久久人人做人人爽综合 | 亚洲欧美另类日本久久国产真实乱对白| 久久久久亚洲AV成人片| 久久久久亚洲av成人网人人软件| 久久久亚洲欧洲日产国码aⅴ| 九九精品久久久久久噜噜| 日韩亚洲国产综合久久久| 久久青青草原综合伊人| 久久久久久亚洲精品成人| 亚洲中文字幕无码久久2020 | 国内精品久久久久久久影视麻豆 | 精品国产日韩久久亚洲| 国产精品九九久久免费视频 | 国产精品久久久久免费a∨| 久久青青草原精品国产不卡| 日本三级久久网| 久久国产乱子精品免费女| 青青青青久久精品国产h| 青草影院天堂男人久久| 国产精品亚洲美女久久久| 久久久受www免费人成| 久久久久一本毛久久久| 久久久久亚洲AV无码专区桃色|