0
votes

I'm working on a project that involves writing a new system call for Linux 3.18.20. This system call is supposed to store various information about the currently running process in a newly defined struct.

One of the fields of the struct is the PID of the process's youngest child, and I've been searching for information about this in the struct task_struct, as defined here: http://lxr.free-electrons.com/source/include/linux/sched.h. I've been testing my new system call, and I can't seem to find the appropriate PID value from the struct list_head children.

My test function involves forking a child, storing the return value of fork, and comparing it to the value I get from doing various things in the parent's task_struct. I got the parent's task_struct, and I tried all of the following macros for struct list_head to get the correct PID. None of them have been correct.

    printk("list_next_entry pid = %d\n", list_next_entry(task, children)->pid);
printk("list_prev_entry pid = %d\n", list_prev_entry(task, children)->pid);
printk("list_entry pid = %d\n", list_entry(&task->children, struct task_struct, children)->pid);
printk("list_first_entry pid = %d\n", list_first_entry(&task->children, struct task_struct, children)->pid);
printk("list_last_entry pid = %d\n", list_last_entry(&task->children, struct task_struct, children)->pid);

Is this even close to the correct way to try to find the youngest child of the parent process? How can I find a process's youngest child's PID from that process's task_struct?

2

2 Answers

0
votes

As comments to fields in task_struct note, children is

list of my children

and siblings is

linkage in my parent's children list

So pointer to the first children task can be requested using

list_first_entry(&task->children, struct task_struct, siblings)
0
votes

One process can get the youngest process pid from it's last fork(2) system call it made. You'll have to patch the clone(2) system call (as it's the base for al fork calls in linux) and store the pid of the returning process in the u-area (or whatever its called in linux kernel) so you can get it from there when the user calls your system call.