Issue
I saw that linux kernel is using struct list_head
to save the children of a process.
What if the process has no forked children? will it return null or not? how may I check if a process has no children?
Solution
The file include/linux/list.h
contains many useful functions for manipulating lists. One of the functions in this file is list_empty()
, which returns the result of checking whether the list head
is equal to itself ( head -> next
), if true, the list is empty.
If the child process list isn't empty, you can use the list_for_each_entry_safe
macro/function to iterate through the list safely.
Answered By - wxz