How to specify a CPU core in Linux with Taskset
Multi-core processing can have many benefits and drawbacks. Sometimes you need to manually assign CPU cores to programs to get best performance. In Linux, the main tool for this purpose is taskset. This may sound intimidating, but we'll break it down into steps to simplify the process.
Basic knowledge of taskset
The use of taskset can be divided into two parts: The CPU's relationship with the programs to be started and with the programs that are run. Launching the program is easier, so let's start from there. The launch command looks like this:
taskset -c number-core-cpu app
Before you enter the number of CPU cores you want to specify, don't forget that the Unix numbering scheme usually starts at 0, so your first core will be 0, the second core will be 1, and so on. Dual core will have cores 0 and 1, while the quad core machine will have cores 0, 1, 2 and 3.
Let's say you want to run Audacity on a dual core system and you want it to run on a second core. The command would be:
taskset -c 1 audacity
Uses multiple cores
On one of the test machines, Chrome would sometimes experience drop frames while streaming video, but it would be okay if assigned to 2 cores. If you want to try the same thing on a quad core system and want to assign Chrome to cores 3 and 4, the command would be:
taskset -c 2,3 google-chrome
You don't have to specify the CPU in sequence, you can randomly select any core. Let's say you have a 6-core machine and want to use Chrome on cores 2 and 6. You would enter the command:
taskset -c 1,5 google-chrome
You can also use hyphens to spread an application across several cores. For example, many old programs or system functions will default to on the first core. What if you wanted to leave the first core as empty as possible, while spreading a large application across all the other cores?
Let's say you have an 8 core system and want to run Steam from 2nd to 8th core. That command would be:
taskset -c 1-7 steam
Change the cores for an already launched program
Taskset isn't just limited to app launch. You can also change the CPU cores for a running program. Before you can change the core of an application, however, you need to know the application's process ID (PID for short) first.
To find out your application's PID, you can try using the desktop's System Monitor tool, but the fastest way is to use the top.
top
The names of all running commands are located on the right side of the screen. The corresponding process IDs are on the left.
Jot down the PID as you'll use it in a moment. For this example we'll be using VLC, which is playing a high definition Matroska video on an old 6-core PC. Different CPU cores are being tested to get the best performance out of VLC.
To change the core for an existing process, the syntax looks like this:
taskset -cp core-numbers PID
As you can see in the screenshot above, VLC's progress ID is 20485. For example we will try running VLC on 4th, 5th and 6th core, under Unix numbering it would be 3-5. So the command would be:
taskset -cp 3-5 20485
But what if you want to test the existing core before changing it? To do that, don't enter any number of cores and taskset will tell you which core is specified. The command changed to:
taskset -cp 20485
It shows that VLC is spread across all cores.
Try it again with another program. Suppose the example runs a large Matroska with SMPlayer instead and SMPlayer has been launched. Top said the PID was 16058.
But first we want to know its existing core. Using the command with the -cp switch but without the number of cores, you can see the program is spreading across all cores.
Now, you can try extending SMPlayer on 3 cores just like testing VLC with the command:
taskset -cp 3-5 16058
You should read it
- Top 5 best Intel CPUs 2022
- What's the difference between Intel Core and Intel Core X CPUs?
- Does your computer need Intel Core i3, i5 or i7?
- Learn about E-Core and P-Core in Intel CPUs
- Intel replaced Core 2 Duo with i3, i5 and i7
- Core i3-12100F Alder Lake could be the fastest quad-core CPU ever made by Intel
- Information about the new generation Intel Core i3 / i5 / i7 mobile processors
- Laptops using chips Core i pressed the Core 2 line for discounts
May be interested
- How to control WiFi network in Linux using Evillimiterfortunately, controlling a wifi network in linux is pretty easy. you can use evillimiter - an open source application - to monitor and control your device's bandwidth.
- How to backup files on Linux to Google Drivethis guide will show how you can automatically back up files in linux to google drive using the open source google-drive-ocamlfuse and cron package.
- How to install VLC Media Player 3 on CentOS 8on centos 8 linux systems, this media player software is not available by default. you will have to install vlc using third-party packages. in this article, tipsmake will join you to learn how to install vlc on centos 8 linux.
- How to install DEB file in Ubuntuhow do you install deb files? there are several ways to install a deb package on ubuntu. the article will show you one by one in this tutorial.
- Tail command in Linuxtail is a complement to the head command. as its name implies, the tail command outputs the last n data numbers of the given input. by default, the tail command prints the last 10 lines of the specified file. if more than one file name is provided then the file name will be preceded by the data from each file.
- How to Install and Use Fonts in Linuxbut while font rendering is far from perfect in linux, one thing this open source platform does well is allow users to easily manage their fonts. from selecting, adding, and adjusting, you can work with fonts quite easily in linux.