Use the taskset command to restrict the CPU of a process

Source: Internet
Author: User

It is often felt that the system resources are insufficient, and no more than three important services can be run on a single machine. However, every day we need to perform backup compression and other operations on the machine, and the network will be transmitted for a long time, this affects the insufficient system resources;

At this time, we can limit some less important tasks, such as copy, backup, and synchronization, to a single CPU or a core of a multi-core CPU, although this is not necessarily the most effective method, it can maximize the use of valid resources to reduce the CPU resources occupied by less important processes;

TasksetIt can help us complete the work, and the operation is very simple;

The tool is installed by default. The RPM package name is util-Linux.

The following example shows how to use a previously written script to consume CPU resources. The original script is a shell script that consumes CPU resources. The following example shows how to exhaust the resources of four CPUs on a 16-CPU machine:

Use the TOP command to see the effect of 4 CPUs running full:

Now you can use the taskset command to adjust the CPU used by these processes:

Taskset-CP 1 25718 taskset-CP 3 25720 taskset-CP 5 25722 taskset-CP 7 25724

In top, let's look at the effect:

Haha, the CPU usage has been provisioned. Similarly, we can make a process use only a few CPUs:

 
Taskset-CP 25718

For more details, see man taskset.

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.