The Parent Child Relationship

Consider a user running a Linux shell, such as bash. This user may type a series of commands, launching some processes that terminate and others that don't. In a GUI environment, a single bash instance might be used to launch a mail reader and a multimedia player, both of which can run simultaneously. From the same shell, the user might run several commands in series, such as Is and cp. All of these programs are known as the children of the shell that launched them. The shell, in turn, is the parent of its children. These relationships can extend for an arbitrary number of generations. For instance, bash is the child of thexterm in which it's running, which in turn is the child of a window manager, another bash instance, or some other process. Any process in this tree can fork multiple children; for instance, the window manager is likely to launch several programs. This set of relationships is illustrated in Figure 14.1. The entire set of processes on a Linux computer is sometimes called the process tree because of the branching nature of these relationships.

Figure 14.1: Linux processes are arranged in a hierarchical structure similar to the structures of tree branches.

Unlike human relationships, the parent/child relationships among Linux programs require just one parent to create a child. Any given process can have no, one, two, three, or more children. Every process has a parent, although the first process has an unusual parent: the kernel. The Linux boot process begins with a boot loader launching the kernel. The kernel, in turn, is hard-coded to look for and run a program called init. This program loads and runs the /etc/inittab configuration file, which controls the rest of the boot process by launching additional programs and startup scripts.

Every process is identified by a unique number, the process ID (PID). The task with a PID of 0 is the kernel, or more precisely the kernel's idle task, which runs when no other process demands CPU time. The PID of init is 1. Beyond init, the PID varies from one system to another, because startup procedures vary from one distribution to another and even from one installation to another. Nonetheless, Linux process management relies on the PID, so there are tools to help you locate the PID for any given process, as described in the upcoming section, "All You Ever Wanted to Know about Your Processes."

0 0

Post a comment