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


            综合久久给合久久狠狠狠97色| 亚洲AV无一区二区三区久久 | 97久久综合精品久久久综合| 亚洲精品蜜桃久久久久久| 午夜精品久久久久久中宇| 久久午夜无码鲁丝片| 精品久久人人妻人人做精品| 久久久久国产视频电影| 性色欲网站人妻丰满中文久久不卡| 久久91精品久久91综合| 99久久做夜夜爱天天做精品| 国内精品久久人妻互换| 久久这里有精品| 久久免费高清视频| 精品久久亚洲中文无码| 青青国产成人久久91网| 久久亚洲精品中文字幕| 香蕉aa三级久久毛片| 99久久久久| 精品免费tv久久久久久久| 东方aⅴ免费观看久久av| 久久无码人妻精品一区二区三区| 亚洲色大成网站www久久九| 亚洲精品美女久久久久99小说| 久久精品人人做人人爽电影| 亚洲精品无码专区久久久| 欧洲性大片xxxxx久久久| 久久综合综合久久狠狠狠97色88| 亚洲中文字幕无码久久2020| 精品国产日韩久久亚洲| 亚洲精品国精品久久99热| 91精品婷婷国产综合久久 | 久久er热视频在这里精品| 精品国产乱码久久久久久人妻 | 久久久久亚洲AV无码专区首JN | 久久se精品一区精品二区国产| 99久久99久久久精品齐齐| AV狠狠色丁香婷婷综合久久| 欧美va久久久噜噜噜久久| 久久丫精品国产亚洲av| 久久精品国产亚洲av日韩|