The Linux process consists of a core process and a normal process. When the normal process is bound to the Linux system CPU core, the normal process becomes the core process. This article uses Ubuntu as an example to introduce how to bind CPU processes in Ubuntu.
taskset -cp "CPU ID |
CPU IDs "Process ID"
The following is a simple example to illustrate how to do this.
1. Sample code with 100% CPU utilization:
class Test {
public static void main(String args[]) {
int i = 0;
while (true) {
i++;
}
}
}
2. Compile and run the above sample code
# 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 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/precision/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)...< Br>
Processing triggers for man-db ...
Setting up htop (1.0.1-1)...
After the installation is complete, execute the command:
# htop
the above views can be seen, CPU2 the utilization rate of 100%, and this process is likely to be assigned to other CPU core run, this distribution is uncertain.
4. Process Binding CPU Core
Run the following command to permanently assign this Java process (process ID number 26502) to CPU No. 5 (CPU core number starts from 0) Therefore, the serial number 4 refers to the CPU core No. 5)
# taskset -cp 5 26531
pid 26531‘s current affinity list: 0-7
pid 26531’ s new affinity list: 5
from the above you can see the view number 6 CPU core utilization as 100%.
The above is how to bind the CPU process in Ubuntu, of course, some CPU cores may be more than one, but no matter which core effect is bound to the same.
There are a lot of commands for Linux system. Today, we mainly introduce Linux syst
Linux has an error message when mounting a USB flash drive, suggesting mount: unkno
When you modify the Linux software source, it prompts Unable to locate package erro
There are many commands in the Linux system. A large part of the Linux rookie learn
Detailed steps for mounting Windows shared files in Linux
Ubuntu installs the fort compiler skills
How to boot a Linux ISO image file from the hard disk
The difference between Apache and Tomcat in Linux system is
How to use Linux to clear Bash environment variables with commands
Linux system file permissions and access mode introduction
How to change the resolution of Red Flag Linux6.0sp1 system
CentOS uses Java method via Chrome
How to install zoneminder software in Linux
Windows 10 Build 10158 Getting Started Video Starter
Windows XP system wants to slow you to teach you quick start skills
Win10 Mobile/PC version of "Windows Camera" application update, upgrade to 5.49.2004
Explore WinXP system file protection function
Windows7 can not open the registry response measures
How to set up shared files in windows 7?
How to use the chown command to change the owner of the Linux file
How to quickly activate the program window under Windows7 system
Microsoft launches Windows 10 subscription service for enterprise users