• <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++博客 首頁 新隨筆 聯(lián)系 聚合 管理
              33 Posts :: 3 Stories :: 27 Comments :: 0 Trackbacks
            在linux下開發(fā)的多線程系統(tǒng)中,每個線程的調(diào)試和監(jiān)控一直比較麻煩,無法精準(zhǔn)定位,現(xiàn)在有了解決辦法了。
            linux下的prctl庫自kernel 2.6.9后支持PR_SET_NAME選項,用于設(shè)置進(jìn)程名字,linux的進(jìn)程一般使用lwp,所以這個函數(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.


            簡單實現(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)在能夠為線程設(shè)置名字了,那么如何看到呢
            ps -eL -o pid,user,lwp,comm
            top 
            -



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

            Feedback

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

            就是說通過prctl () 這個接口設(shè)置thread 名字后,如何驗證啊?
            用top命令 或者pgrep 之類的
              回復(fù)  更多評論
              

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


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


            国产精品视频久久久| 久久精品国产精品亚洲艾草网美妙| 伊人情人综合成人久久网小说| 久久综合色老色| 亚洲综合精品香蕉久久网97| 香蕉久久夜色精品国产尤物| 国产精品久久久久久福利69堂| 四虎影视久久久免费| 国产国产成人精品久久| 亚洲精品无码久久久| 国产成人无码精品久久久免费| 亚洲精品无码久久久影院相关影片 | 久久免费视频网站| 一日本道伊人久久综合影| 国产精品岛国久久久久| 亚洲欧美国产精品专区久久| 久久精品国产亚洲精品2020| 国产伊人久久| 亚洲国产精品久久久久| 久久亚洲AV成人出白浆无码国产 | 中文字幕久久波多野结衣av| 久久青草国产精品一区| 久久久女人与动物群交毛片| 久久久久亚洲国产| 色偷偷91久久综合噜噜噜噜| 久久夜色精品国产亚洲| 久久亚洲国产成人精品性色| 久久综合88熟人妻| 一本色道久久99一综合| 99久久综合国产精品免费| 欧美性大战久久久久久| 久久精品国产精品亚洲人人| 九九久久精品无码专区| 国产精品免费看久久久香蕉| 国产精品99久久久久久董美香| 精品久久久久久国产91| 国产精品久久永久免费| 老司机国内精品久久久久| 精品久久久久久无码人妻热| 久久久久国产一级毛片高清板| 日韩中文久久|