Internal organization (with regard to family relations) of processes in Linux

fork() creates a new process by copying the process descriptor. Hence the two processes do share (at least initially) some data, but as soon as one process starts changing it, copy-on-write mechanism make sure the change is localized only to the process that actually made it. It is the standard mechanism for process spawning on UNIX.

This of course creates a rather natural parent-children relation between processes, yet this is independent of the internal representation in the kernel. Process descriptors can be implemented as a linked list, tree, hash table or any other (more or less) suitable structure. All that one really needs is place in the kernel process descriptor that points to the parent process (and possibly child processes as well). Whether it is or isn't used as a key part of the structure is a design decision. One of the many things that come into play when deciding such a thing is for example what happens once the parent process exits - on UNIX the init process adopts orphaned processes (with all of their children processes).


Your confusion stems from mixing two things: (1) keeping the process descriptors organized, and (2) the parent/child relationship.

You don't need the parent/child relationship to decide which process to run next, or (in general) which process to deliver a signal to. So, the Linux task_struct (which I found in linux/sched.h for the 3.11.5 kernel source) has:

struct task_struct __rcu *real_parent; /* real parent process */
struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports */
/*
 * children/sibling forms the list of my natural children
 */

struct list_head children;  /* list of my children */
struct list_head sibling;   /* linkage in my parent's children list */

You're correct, a tree struct exists for the child/parent relationship, but it seems to be concealed in another list, and a pointer to the parent.

The famed doubly-linked list isn't obvious in the 3.11.5 struct task_struct structure definition. If I read the code correctly, the uncommented struct element struct list_head tasks; is the "organizing" doubly-linked list, but I could be wrong.