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

            牽著老婆滿街逛

            嚴以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            Linux下多CPU中進程與CPU綁定的例子

            轉載自:http://www.chinaunix.net/jh/4/904906.html

            現在多CPU的趨勢越來越大了. 有時候為了更好地操作機器, 需要將某個進程綁定到具體的CPU上去. 下面給出了一個進程綁定到具體的CPU上去的一個例子.  

            #include<stdlib.h> 
            #include
            <stdio.h> 
            #include
            <sys/types.h> 
            #include
            <sys/sysinfo.h> 
            #include
            <unistd.h> 

            #define __USE_GNU 
            #include
            <sched.h> 
            #include
            <ctype.h> 
            #include
            <string.h> 

            int main(int argc, char* argv[]) 

                    
            int num = sysconf(_SC_NPROCESSORS_CONF); 
                    
            int created_thread = 0
                    
            int myid; 
                    
            int i; 
                    
            int j = 0

                    cpu_set_t mask; 
                    cpu_set_t 
            get

                    
            if (argc != 2
                    

                            printf(
            "usage : ./cpu num\n"); 
                            exit(
            1); 
                    }
             

                    myid 
            = atoi(argv[1]); 

                    printf(
            "system has %i processor(s). \n", num); 

                    CPU_ZERO(
            &mask); 
                    CPU_SET(myid, 
            &mask); 

                    
            if (sched_setaffinity(0sizeof(mask), &mask) == -1
                    

                            printf(
            "warning: could not set CPU affinity, continuing\n"); 
                    }
             
                    
            while (1
                    


                            CPU_ZERO(
            &get); 
                            
            if (sched_getaffinity(0sizeof(get), &get== -1
                            

                                    printf(
            "warning: cound not get cpu affinity, continuing\n"); 
                            }
             
                            
            for (i = 0; i < num; i++
                            

                                    
            if (CPU_ISSET(i, &get)) 
                                    

                                            printf(
            "this process %d is running processor : %d\n",getpid(), i); 
                                    }
             
                            }
             
                    }
             
                    
            return 0
            }
             


            下面是在兩個終端分別執行了./cpu 0  ./cpu 2 后得到的結果. 效果比較明顯.  
            Cpu0  :  5.3%us,  5.3%sy,  0.0%ni, 87.4%id,  0.0%wa,  0.0%hi,  2.0%si,  0.0%st 
            Cpu1  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st 
            Cpu2  :  5.0%us, 12.2%sy,  0.0%ni, 82.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st 
            Cpu3  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st 
            Cpu4  :  0.0%us,  0.0%sy,  0.0%ni, 99.7%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st 
            Cpu5  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st 
            Cpu6  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st 
            Cpu7  :  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st 

            posted on 2010-10-31 15:54 楊粼波 閱讀(968) 評論(0)  編輯 收藏 引用

            日韩人妻无码精品久久久不卡| 国产精品一久久香蕉产线看| 久久伊人五月天论坛| 久久这里有精品视频| 亚洲欧洲日产国码无码久久99| 精品熟女少妇a∨免费久久| 99久久免费国产精品| 精品人妻伦九区久久AAA片69| 久久精品国产91久久麻豆自制| 武侠古典久久婷婷狼人伊人| 国产韩国精品一区二区三区久久| 欧美与黑人午夜性猛交久久久| 精品久久久久久久久午夜福利| 久久99亚洲综合精品首页| 三上悠亚久久精品| 久久综合给合综合久久| 国产精品久久久久久影院 | 久久久国产精品| 99久久人妻无码精品系列| 精品久久人人妻人人做精品| 色狠狠久久AV五月综合| 久久AV高潮AV无码AV| 人妻无码精品久久亚瑟影视| 久久久久久青草大香综合精品| 久久w5ww成w人免费| 一本色道久久HEZYO无码| 久久婷婷五月综合97色直播| 久久久黄色大片| 综合久久精品色| 一本久久综合亚洲鲁鲁五月天| 久久国产成人| 亚洲а∨天堂久久精品9966| 久久人妻少妇嫩草AV无码蜜桃| 国产亚州精品女人久久久久久| 国产91久久精品一区二区| 精品久久久久久国产91| 久久久久久a亚洲欧洲aⅴ| 日本久久久久久中文字幕| 久久超乳爆乳中文字幕| 欧美日韩中文字幕久久伊人| 久久99国产精品二区不卡|