Bind CPU to processes in Centos

Source: Internet
Author: User
Taskset is a CPU adjustment tool that can assign system tasks to the specified CPU this article takes nodejs as an example of the first step, query the nodejs process pgrepnode1927719283 step 2, lock the CPUtaskset-pc019277 (where 0 represents CPU0, and so on) taskset-pc119283 step 3, get it done! A small script is provided to automatically bind nodejs processes. assume that there are four nodes and the CPU is quad-core.

Taskset is a CPU adjustment tool that can allocate system tasks to a specified CPU.


This document takes nodejs as an example.


Step 1: query the nodejs process

pgrep node1927719283

Step 2: Lock the CPU

Taskset-pc 0 19277 (0 indicates CPU0, and so on) taskset-pc 1 19283

Step 3: Get it done!


A small script can be attached to automatically bind nodejs processes. assume that there are four nodes, and the CPU is quad-core.

#!/usr/bin/env bashset-enode_porcess=`pgrep node|wc-l`if[$node_process -eq0 ];thenecho“nodejs process not found”exit1elsenode1=`pgrep node |sort|tr-s "\n"" "|awk'{print $1}'`node2=`pgrep node |sort|tr-s "\n"" "|awk'{print $2}'`node3=`pgrep node |sort|tr-s "\n"" "|awk'{print $3}'`node4=`pgrep node |sort|tr-s "\n"" "|awk'{print $4}'`taskset -pc 0 $node1taskset -pc 1 $node2taskset -pc 2 $node3taskset -pc 3 $node4fi

This article is from the "Purple_Grape blog", please be sure to keep this source http://purplegrape.blog.51cto.com/1330104/1252197


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.