I am trying to traverse all the ancestors of a process to store their info in a static array passed by the user, and I am using the NULL pointer end flag to end traversing. However, this does not seem to work, and will continue looping until the size number (the capacity of the array) passed by the user space matches num_filed number (the number of elements in the array) in all cases, even if I have very little number of processes running. So, what seem to be the ending flag for traversing ancestors? Here is my traversing loop code:
current_process = current;
int i = 0;
while (current_process != NULL && current_num_filled < size) {
temp_info_array[i] = get_process_info(current_process);
++current_num_filled;
++i;
current_process = current_process->parent;
}