This is my solution so far:
int is_descendant(task_t* ansc, task_t* targ)
{
task_t* p_tmp;
for(p_tmp = targ ; (p_tmp) && (ansc) && (p_tmp->pid) && (p_tmp->pid != ansc->pid) ; p_tmp = p_tmp->p_pptr) ;
if((!p_tmp) || (!current) || (!p_tmp->pid)) return -ESRCH;
return 0;
}
It works but I'm unsure about several things:
without checking if
p_tmp->pid == 0
it iterates forever, does that mean that the parent pointer of the first process is not NULL ?is it necessary to check if
p_tmp
oransc
are NULL ?is there a better way to do this ? (using O(1) space compl.)
macro vs. function ?
Thanks