• <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è)置進程名字,linux的進程一般使用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 :進程號
            tid : 線程號  回復(fù)  更多評論
              


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


            欧美麻豆久久久久久中文| 久久精品国产精品国产精品污| 久久久久久一区国产精品| 久久精品国产亚洲AV不卡| 中文字幕乱码久久午夜| 久久精品成人免费网站| 一本久久a久久精品vr综合| 久久免费视频网站| 国产成年无码久久久免费| 精品久久久久中文字幕一区| 久久无码中文字幕东京热| 国产精品综合久久第一页| 久久精品亚洲中文字幕无码麻豆 | 久久综合亚洲色HEZYO国产| 日产精品久久久久久久| 老司机午夜网站国内精品久久久久久久久 | 久久久久亚洲av无码专区| 日韩欧美亚洲国产精品字幕久久久| 久久精品麻豆日日躁夜夜躁| 国产99久久久国产精品小说| 久久se精品一区精品二区| 日本久久久久亚洲中字幕| 热久久视久久精品18| 人妻无码久久精品| 无码乱码观看精品久久| 久久久久噜噜噜亚洲熟女综合| 91久久精品国产成人久久| 久久国产精品成人免费| 久久精品无码专区免费东京热| 国产精品久久久久久久久久影院| 久久国产精品免费一区二区三区| 精品国产一区二区三区久久| 国产精品一区二区久久| 国产亚洲婷婷香蕉久久精品| 久久99久久99小草精品免视看 | 久久久久国产精品嫩草影院| 亚洲AV伊人久久青青草原| 欧美午夜A∨大片久久| 中文精品99久久国产| 久久天天躁狠狠躁夜夜不卡| 一本一道久久综合狠狠老|