11

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?

nrz
  • 10,435
  • 4
  • 39
  • 71
David
  • 4,634
  • 7
  • 35
  • 42

1 Answers1

16

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.

Dan Aloni
  • 3,968
  • 22
  • 30