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