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


            簡單實現代碼:

            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) ;

            }

            現在能夠為線程設置名字了,那么如何看到呢
            ps -eL -o pid,user,lwp,comm
            top 
            -



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

            Feedback

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

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

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

            久久亚洲国产精品123区| 久久93精品国产91久久综合| 久久这里只有精品首页| 2021久久精品免费观看| 久久婷婷成人综合色综合| 亚洲国产成人久久精品动漫| 久久中文字幕视频、最近更新 | 久久人人爽人人爽人人片AV麻豆 | 99久久国产综合精品成人影院| 久久国产香蕉一区精品| 亚洲国产欧美国产综合久久| 成人午夜精品久久久久久久小说| 国产精品一区二区久久精品涩爱| 精品国产乱码久久久久久郑州公司| 久久久久亚洲AV无码去区首| 久久精品国产亚洲AV电影| 久久午夜综合久久| 国产一区二区三区久久| 久久天天躁狠狠躁夜夜不卡| 中文字幕亚洲综合久久| 无码精品久久久久久人妻中字| 久久久精品国产亚洲成人满18免费网站 | 久久99精品国产麻豆婷婷| 午夜人妻久久久久久久久| 国产精品日韩欧美久久综合| 久久久免费精品re6| 欧美日韩精品久久久免费观看| 久久99精品国产麻豆婷婷| 亚洲综合精品香蕉久久网97| 欧美精品久久久久久久自慰| 久久久国产精华液| 久久久久国产| 国内精品久久久久影院网站| 久久99中文字幕久久| 久久精品国产亚洲AV无码偷窥| 久久99精品久久久大学生| 色狠狠久久综合网| 久久亚洲精品国产亚洲老地址 | 久久精品国产亚洲AV香蕉| 亚洲欧洲久久久精品| 国产精品久久久久久久久软件|