简体   繁体   English

添加条目到task_struct并初始化为默认值

[英]Adding entry to task_struct and initializing to default value

I want to add an entry to process control block structure ( task_struct ). 我想在进程控制块结构( task_struct )中添加一个条目。 Let say a way to tag some process. 让我们说一种标记某个过程的方法。 I want to initialize this field to 0 for all the process except "some special processes", later by calling sched_setscheduler() I will set this flag for the "special processes". 我想将此字段初始化为0,除了“一些特殊进程”之外的所有进程,稍后通过调用sched_setscheduler()我将为“特殊进程”设置此标志。

Does anybody have an idea how to assign a default value to a member variable in task_struct ? 有没有人知道如何在task_struct为成员变量分配默认值?

I'm assuming you are talking about a recent Linux kernel, because implementation detail changes over time. 我假设您正在谈论最近的Linux内核,因为实现细节会随着时间而变化。

There are two options. 有两种选择。 The first - you can set the value of the variable in the init_task global. 第一个 - 您可以在init_task全局中设置变量的值。 See how it is done in the linux/init_task.h header. 看看它是如何在linux/init_task.h头文件中完成的。 The second option is to add code to copy_process , which you might want to do anyway in order to properly handle the fork() inheritance of the field you are adding. 第二个选项是将代码添加到copy_process ,您可能希望这样做,以便正确处理要添加的字段的fork()继承。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM