无法获得处理器关联性(Linux)

时间:2018-07-10 11:20:51

标签: c++ linux affinity

我正在尝试使用亲缘性掩码,并使用CPU_ISSET()将其制成逗号分隔的字符串。然后,我需要在其前面添加字符串“ taskset -c”,并在其后添加可执行文件,以创建Linux命令。

当我将cpu编号添加到数组并打印时,输出不正确。

为了运行Linux命令,我需要数组最终输出为字符串。

        services.AddIdentity<MyUser, MyRole>(options => {
            options.Password.RequireDigit = true;
            options.Password.RequiredLength = 6;
            options.Password.RequireNonAlphanumeric = false;
            options.Password.RequireUppercase = false;
            options.Password.RequireLowercase = false;
            options.SignIn.RequireConfirmedEmail = false;
        })
        .AddUserStore<MyUserStore>()
        .AddRoleStore<RoleStore>();


        services.AddAuthentication(options => {
            options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
        })
        .AddIdentityServerAuthentication(options => {
            options.Authority = "https://localhost:44347";
            options.RequireHttpsMetadata = false;

            options.ApiName = API_NAME;
        });

输出是一吨零,然后是随机数。

1 个答案:

答案 0 :(得分:0)

您忘了装上口罩了,可以这样做:

sched_getaffinity (getpid (), CPU_SETSIZE, &mask);

仅此而已。


编辑:

我之前没有注意到,但是即使您进行了编辑,这些循环还是有缺陷的。对于第一个,请执行以下操作:

for (int i = 0; i < CPU_SETSIZE; i++)
    temp [i] = (CPU_ISSET (i, &mask)) ? i : -1;

第二步,做:

for (int i : temp)
{
    if (i >= 0)
        os << i;
}

当然,将temp声明为:

int temp [CPU_SETSIZE];

那么您应该开始获得一些明智的结果。

建议:更加注重细节。如果不这样做,您将一事无成。接受这个答案会很不错,因为我已经为您整理了所有东西。

相关问题