问题
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