I want to add new field ( to store number of ready process of this user ) to user_struct in file linux-source/kernel/user.c
struct user_struct {
atomic_t ready_processes; /* I add this field */
/* not important fields */
}
where to initialize this field correctly ?
In order to add a new field to user_struct
, you need to do 3 things:
Definition of user_struct
is in file sched.h(include/linux/sched.h)
You should add your field in that struct
.
struct user_struct {
atomic_t ready_processes; /* I added this line! */
/*Other fields*/
};
In user.c (kernel/user.c) line 51, user_struct
is instantiated for root_user
globally. Give your field a value here.
struct user_struct root_user = {
.ready_processes = ATOMIC_INIT(1), /* I added this line! */
.__count = ATOMIC_INIT(2),
.processes = ATOMIC_INIT(1),
.files = ATOMIC_INIT(0),
.sigpending = ATOMIC_INIT(0),
.locked_shm = 0,
.user_ns = &init_user_ns,
};
You're done with initializing your field for root user but you should also initialize it for other users.
For this aim, in user.c, go to the function alloc_uid
where new users get allocated and initialized. For example you see there's a line atomic_set(&new->__count, 1);
that initializes __count
. Add your initialization code beside this.
atomic_set(&new->__count, 1);
atomic_set(&new->ready_processes, 1); /* I added this line! */
NOTE: It works in linux 2.6.32.62. I'm not sure about other versions but I think it shouldn't be very different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With