将一个已经运行的进程attach到固定CPU内核上的方法(linux,windows)

本文介绍如何使用taskset命令在Linux环境下为MySQL等进程指定运行的CPU核心,以实现更高效的资源利用。包括查看和设置进程CPU亲和性的具体操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

       在此前工作中对mysql的调优中曾经使用过该命令,将mysql的实例在制定的若干CPU内核上执行。

 

Retrieve the CPU affinity of an existing task

The general syntax is as follows:
taskset -p [pid]
To retrieve the CPU affinity of an existing task (PID 12345), enter:
# taskset -p 12345

Use taskset command to CPU affinity

The general syntax is as follows:
taskset -c [0,1,2,3..N] [pid]
Where,

  • -c 0,1,2,..N : The masks are typically given in hexadecimal. For example, 0x00000001 is processor #0, 0x00000003 is processors #0 and #1 etc. However -c option allows you to specifiy a numerical list of processors instead of a bitmask. The list may contain multiple items, separated by comma, and ranges. For example, 0,5,7,9-11.
    : Process / program ID
  • pid

For example set PID 12345 on 2-3 CPU, enter:
# taskset -c 2,3 12345

 

参见:http://www.cyberciti.biz/faq/taskset-cpu-affinity-command/

 

windows多核环境可以在任务管理器中图形化设置比较方便,如下图:

如果mysql是允许在windows环境,可以通过这种方法来调优。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值