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


            7777久久亚洲中文字幕| 91精品国产综合久久久久久| 久久笫一福利免费导航| 人妻少妇久久中文字幕| 国产午夜福利精品久久2021| 久久久精品波多野结衣| 日日躁夜夜躁狠狠久久AV| 国产高潮国产高潮久久久91 | 国产精品免费久久久久电影网| 精品久久久久久无码人妻热| 77777亚洲午夜久久多喷| 伊人久久综合精品无码AV专区| 香蕉久久永久视频| 国产午夜久久影院| 伊人久久大香线蕉av不卡| 久久精品国产半推半就| 97久久婷婷五月综合色d啪蜜芽| avtt天堂网久久精品| 久久精品国产亚洲Aⅴ香蕉| 久久精品二区| 久久久久人妻一区精品色| 伊人久久精品线影院| 一本色综合久久| 精品国产乱码久久久久久1区2区 | 伊人久久大香线蕉av不卡| 99久久精品免费国产大片| 99久久99这里只有免费费精品 | 94久久国产乱子伦精品免费| 久久精品九九亚洲精品| 武侠古典久久婷婷狼人伊人| 久久亚洲2019中文字幕| 无码人妻少妇久久中文字幕| 伊人 久久 精品| 久久91综合国产91久久精品| 97久久精品国产精品青草| 国产精品成人精品久久久 | 久久久久国色AV免费看图片| 无码国内精品久久人妻麻豆按摩| 久久久久国产一区二区三区| 成人综合久久精品色婷婷| 亚洲狠狠婷婷综合久久久久|