系統(tǒng)之家 - 系統(tǒng)光盤下載網(wǎng)站!

當(dāng)前位置:系統(tǒng)之家 > 系統(tǒng)教程 > Ubuntu綁定CPU進(jìn)程

在Ubuntu中怎么綁定CPU進(jìn)程?

時(shí)間:2015-08-05 13:59:33 作者:zhijie 來(lái)源:系統(tǒng)之家 1. 掃描二維碼隨時(shí)看資訊 2. 請(qǐng)使用手機(jī)瀏覽器訪問(wèn): https://m.xitongzhijia.net/xtjc/20150805/54755.html 手機(jī)查看 評(píng)論

  Linux進(jìn)程包括核心進(jìn)程和普通進(jìn)程,把普通進(jìn)程綁定到Linux系統(tǒng)CPU核中運(yùn)行,那么普通進(jìn)程就成了核心進(jìn)程。本文就以Ubuntu為例子來(lái)介紹一下,在Ubuntu中怎么綁定CPU進(jìn)程。

  taskset -cp 《CPU ID | CPU IDs》 《Process ID》

  下面用一個(gè)簡(jiǎn)單的例子來(lái)說(shuō)明怎樣做到。

  1. CPU利用率達(dá)100%的樣例代碼:

  class Test {

  public static void main(String args[]) {

  int i = 0;

  while (true) {

  i++;

  }

  }

  }

  2. 編譯并運(yùn)行上面的樣例代碼

  # javac Test.java

  # java Test &

 。1] 26531

  3. 使用htop命令查看CPU的利用率

  如果未安裝htop工具,執(zhí)行下面的命令:

  # apt-get install htop

  Reading package lists... Done

  Building dependency tree

  Reading state information... Done

  The following NEW packages will be installed:

  htop

  0 upgraded, 1 newly installed, 0 to remove and 41 not upgraded.

  Need to get 66.9 kB of archives.

  After this operation, 183 kB of additional disk space will be used.

  Get:1 https://mirrors.163.com/ubuntu/ precise/universe htop amd64 1.0.1-1 [66.9 kB]

  Fetched 66.9 kB in 0s (163 kB/s)

  Selecting previously unselected package htop.

 。≧eading database ... 57100 files and directories currently installed.)

  Unpacking htop (from .../htop_1.0.1-1_amd64.deb)...

  Processing triggers for man-db ...

  Setting up htop (1.0.1-1)...

  安裝完成后,執(zhí)行命令:

  # htop

在Ubuntu中怎么綁定CPU進(jìn)程?

  上面的視圖可以看到,CPU2的利用率達(dá)到100%,且這個(gè)進(jìn)程有可能被分配到其它CPU核上運(yùn)行,這個(gè)分配是不定的。

  4. 進(jìn)程綁定CPU核

  運(yùn)行以下命令,把此Java進(jìn)程(進(jìn)程ID號(hào)為26502)永久的分配給5號(hào)CPU核(CPU核號(hào)從0開始計(jì)算,因此序號(hào)4指的是5號(hào)CPU核)

  # taskset -cp 5 26531

  pid 26531‘s current affinity list: 0-7

  pid 26531’s new affinity list: 5

在Ubuntu中怎么綁定CPU進(jìn)程?

  從上面的視圖中可以看到6號(hào)CPU核的利用率為100%。

  以上就是在Ubuntu中怎么綁定CPU進(jìn)程的介紹了,當(dāng)然有些CPU核可能不只一個(gè),不過(guò)不管綁定到哪個(gè)核效果都是一樣的。

標(biāo)簽 進(jìn)程

發(fā)表評(píng)論

0

沒(méi)有更多評(píng)論了

評(píng)論就這些咯,讓大家也知道你的獨(dú)特見解

立即評(píng)論

以上留言僅代表用戶個(gè)人觀點(diǎn),不代表系統(tǒng)之家立場(chǎng)

其他版本軟件

熱門教程

人氣教程排行

Linux系統(tǒng)推薦

掃碼關(guān)注
掃碼關(guān)注

掃碼關(guān)注 官方交流群 軟件收錄