Adding entry to task_struct and initializing to default value

ε祈祈猫儿з 提交于 2019-12-08 16:45:40

问题


I want to add an entry to process control block structure (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".

Does anybody have an idea how to assign a default value to a member variable in task_struct?


回答1:


I'm assuming you are talking about a recent Linux kernel, because implementation detail changes over time.

There are two options. The first - you can set the value of the variable in the init_task global. See how it is done in the linux/init_task.h header. 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.



来源:https://stackoverflow.com/questions/8044652/adding-entry-to-task-struct-and-initializing-to-default-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!