Ubuntu system process bound CPU core

Source: Internet
Author: User

Ubuntu system process bound CPU core CHSZS, copyright, without consent, may not be reproduced. Blogger Home: Http://blog.csdn.net/chszs

This article describes how to bind a specified process to a specified CPU core operation in an Ubuntu system. It is usually the operating system that manages the scheduling of processes and threads, but in this case it is unclear which CPU cores run your process, because the scheduling of the operating system is based on the availability of resources.

This allows you to bind the specified CPU core to your process.

taskset -cp <CPU ID | CPU IDs> <Process ID>

Here's a simple example of how to do this.

1. Sample code with CPU utilization up to 100%:
class Test {    public static void main(String args[]) {        int i = 0;        while (true) {            i++;        }    }}
2. Compile and run the example code above
# javac Test.java# java Test &[1] 26531
3. Use the Htop command to view CPU utilization

If the Htop tool is not installed, execute the following command:

# apt-get install htopReading package lists... DoneBuilding dependency tree       Reading state information... DoneThe following NEW packages will be installed:  htop0 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) ...

After the installation is complete, execute the command:

# htop


The above view can see that the utilization of the CPU2 reaches 100%, and that the process is likely to be allocated to other CPU cores to run, and this allocation is variable.

4. Process-bound CPU cores

Run the following command to permanently assign the Java process (process ID number 26502) to the 5th CPU core (CPU nuclear number is calculated from 0, so sequence 4 refers to the 5th CPU core)

# taskset -cp 5 26531pid 26531‘s current affinity list: 0-7pid 26531‘s new affinity list: 5


From the view above, you can see that the 6th CPU core utilization is 100%.

Copyright NOTICE: This article for Bo Master Chszs original article, without Bo Master permission not reproduced.

Ubuntu system process bound CPU core

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.