linux怎么把进程绑定到指定的cpu上,linux教程

Linux最近较为热门的行业,很多学者们都问linux的进程有哪些,运行当中怎么处理。其实linux进程包括核心进程和普通进程,把普通进程绑定到Linux系统CPU核中运行,那么普通进程就成了核心进程。小编下面的linux教程就以Ubuntu为例子来介绍一下,在Ubuntu中该如何绑定CPU进程呢?

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

下面用一个简单的例子来说明怎样做到。

1. CPU利用率达100%的样例代码:

class Test {

public static void main(String args[]) {

int i = 0;

while (true) {

i++;

}

}

}

2. 编译并运行上面的样例代码

# Javac Test.java

# java Test &

[1] 26531

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

如果未安装htop工具,执行下面的命令:

# 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 http://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.

(Reading 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)...

安装完成后,执行命令:

# htop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值