PDA

View Full Version : how to get the process data structure through pid?


billconan
January 18th, 2009, 20:34
hello guys,


i'm required to modify the process scheduling part of the freebsd kernel as part of our homework.

the homework needs us add a new variable to the process data structure, and the priority of the process will be having something to do with the variable.

to adjust the variable while the process is running, we also required to write a system call to modify the variable on the fly.

the problem is how to get the process data structure via the pid in the syscall routine?

i'm not familiar with bsd nor linux. i noticed that there is a function called find_task_by_pid that can do this, but i did find identical under freebsd.

my second question is, to finish this homework, we need to modify the runq_choose function defined under the kern_switch.c

problem is, according to the homework requirement, we want only the "real time" and "time sharing" processes to use the new scheduling strategy. but how can i know the type of the running queue in that function? i've noticed a variable called pri, is that a hint of the type of the running queue?

thank you.

mjguzik
January 24th, 2009, 07:57
the problem is how to get the process data structure via the pid in the syscall routine?

You can use pfind - it returns locked process or NULL. Remember to iterate through all threads. (See sched_nice().)


my second question is, to finish this homework, we need to modify the runq_choose function defined under the kern_switch.c

problem is, according to the homework requirement, we want only the "real time" and "time sharing" processes to use the new scheduling strategy. but how can i know the type of the running queue in that function? i've noticed a variable called pri, is that a hint of the type of the running queue?

After taking a quick look I suggest the following (I'm not sure about correctness):
See pri_to_rtp() (sys/kern/kern_resource.c). I'm not sure if variable 'pri' is useful in this case. You can always check td_pri_class of the first thread.

Good luck.