Use the Taskset command to limit the CPU of a process

Source: Internet
Author: User

Often feel that the system resources are not enough, a machine ran on less than 3 more important services, but every day we have to do a backup compression, such as processing, the network for a long time transmission, which is very influential in this is not enough to use the system resources;

At this point, we can limit some of the less important things, such as copy/Backup/synchronization, to one CPU or one core of a multicore CPU, although this is not necessarily the most efficient approach, but it can be used to the greatest extent possible with efficient resources, reducing the CPU resources of less important processes ;

Taskset can help us do the work, and the operation is very simple;

The tool system is installed by default, RPM package name Util-linux

With an example, a shell script that consumes CPU resources, using a previously written script that consumes CPU, exhausts the resources of 4 CPUs on a 16-CPU machine:

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

You can now use the Taskset command to adjust the CPU used by these processes:

TASKSET-CP 1  25718taskset-cp 3  25720taskset-cp 5  25722taskset-cp 7  25724

Look at the effect in top:

Haha, CPU usage has been provisioned, and we can make a process use only a few of these CPUs:

TASKSET-CP  25718

More detailed information can be viewed with the man taskset.

Use the Taskset command to limit the CPU of a process

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.