Centos下為進程綁定CPU

來源:互聯網
上載者:User

taskset 是一個CPU 調節工具,能夠將系統任務分配至指定的CPU


本文以nodejs為例


第一步,查詢nodejs 進程

pgrep node1927719283

第二步,鎖定CPU

taskset -pc 0 19277  (其中0代表CPU0,以此類推)taskset -pc 1 19283

第三步,搞定!


附一個小指令碼,能自動綁定nodejs的進程,假設有四個node,CPU是四核的。

#!/usr/bin/env bashset-enode_porcess=`pgrep node|wc-l`if[$node_process -eq0 ];thenecho“nodejs process not found”exit1elsenode1=`pgrep node |sort|tr-s "\n"" "|awk'{print $1}'`node2=`pgrep node |sort|tr-s "\n"" "|awk'{print $2}'`node3=`pgrep node |sort|tr-s "\n"" "|awk'{print $3}'`node4=`pgrep node |sort|tr-s "\n"" "|awk'{print $4}'`taskset -pc 0 $node1taskset -pc 1 $node2taskset -pc 2 $node3taskset -pc 3 $node4fi

本文出自 “Purple_Grape的部落格” 部落格,請務必保留此出處http://purplegrape.blog.51cto.com/1330104/1252197


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.