在linux上从一开始就设置进程的cpu亲和力 [英] setting cpu affinity of a process from the start on linux

查看:21
本文介绍了在linux上从一开始就设置进程的cpu亲和力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在linux上设置一个进程启动时的cpu亲和力.

I want to set the cpu affinity of a process on linux when it is starting.

有sched_setaffinity、taskset等方法,但需要进程的processid.它们可能会导致潜在的迁移,就像在一个核心上启动了一个进程,但在使用 sched_setaffinity/taskset 之后,它们被迁移到了另一个核心.

There are methods like sched_setaffinity and taskset, but they need the processid of the process. They may cause potential migration like a process was started on a core but after the use of sched_setaffinity/taskset, they were migrated to another core.

我想做的是从头开始在特定核心上启动一个新进程.

What I want to do is to start a new process on a specific core from the beginning.

推荐答案

taskset既可以用来设置正在运行的进程的亲和性,也可以用来启动具有一定亲和性的进程,见

taskset can be used both to set the affinity of a running process or to launch a process with a certain affinity, see

概要

taskset [options] mask command [arg]...
taskset [options] -p [mask] pid

以下命令将在 CPU 1 & 中启动 Google Chrome 浏览器2(或 0 和 1).掩码为 0×00000003,命令为google-chrome".

The below command will launch Google Chrome browser in CPU 1 & 2 (or 0 and 1). The mask is 0×00000003 and command is "google-chrome".

taskset 0×00000003 google-chrome

这篇关于在linux上从一开始就设置进程的cpu亲和力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆