0

I am practicing making device driver programming.

my goal was to get current task's pid, and parent task's pid.

furthermore, I get grand(parent's parent) task's pid.

this is source code.

struct task_struct * current_task = current;
struct task_struct * parent_task = current_task->parent;

printk("current pid : %d, current_task->pid);
printk("parent task pid : %d\n", parent_task->pid);
printk("grand pid : %d\n", parent_task->parent->pid);

this is result.. (I ran this 3 times.)

current pid : 2850 parent task pid : 2846 grand parent task : 1692

current pid : 2872 parent task pid : 2864 grand parent task : 1692

current pid : 2891 parent task pid : 2887 grand parent task : 1692

grand parent task's pid is always 1692.

current's one and parent's one are increasing. I am just wondering why... It will be helpful if someone answer me.. Thanks for reading.

Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
Rast
  • 9
  • 1
  • 5
    There is nice [explanation here on SO](http://stackoverflow.com/questions/3446727/how-does-linux-determine-the-next-pid) – dahrens Oct 02 '16 at 07:58

1 Answers1

0

you have not specified whether you are using IDE for writing and executing the code. In the case if you are using it

grand parent task is IDE (which is constant till you close and reopen it.

parent task id - when you execute the program, the program is called by a process which is created by the IDE and each time you run the program it is called by new processes created by IDE (when you program terminates, the calling process created by your IDE is also terminates). current pid is your process id

Process ID's are assigned in increment order by os.

Rafih_m
  • 76
  • 4