Chapter 9. Process Relationships - Shichao's Notes
The rationale is that unix system calls (at least originally) are "elementary" operations done by the kernel. In practice, applications often do some specific things. Today, I want to talk about UNIX processes, more specifically, how processes . Parent-to-child relationship in terminals and interactive shells. The Unix file system has a hierarchical (or tree-like) structure with its highest level Similar to the concept of the process parent-child relationship, all files on a Unix is the directory where many commonly used executable commands reside.
We discussed that every process has a parent process, this can bring a question that what will happen to a child process whose parent process is killed? Well, this is a good question but lets come back to it sometime later. The init Process When Linux system is booted, First thing that gets loaded into memory is vmlinuz.
It is the compressed Linux kernel executable. This results in the creation of init process. This is the first process that gets created. Init process has PID of one, and is the super parent of all the processes in a Linux session.
If you consider Linux process structure as a tree then init is the starting node of that tree. To confirm that init is the first process, you can run the pstree command on your Linux box. This command displays the tree of processes for a Linux session. Here is a sample output: The output confirms that init is at the top of process tree. Also, if you observe the text in bold, you will see the complete parent child relation of pstree process.
Read more about pstree in our article on tree and pstree. Now, lets come back to the question we left open in the last section about the consequences when parent process gets killed while child is still alive. Well in this case, the child obviously becomes orphan but is adopted by the init process. So, init process becomes the new parent of those child processes whose parents are terminated.
Process Life Cycle In this section, we will discuss the life cycle of a normal Linux process covers before it is killed and removed from kernel process table. As already discussed, a new process is created through fork and if a new executable is to be run then exec family of functions is called after fork.
As soon as this new process is created, it gets queued into the queue of processes that are ready to run. The second type of file listed above is a special file called a directory please don't call it a folder? Directory files act as a container for other files, of any category. Thus we can have a directory file contained within a directory file this is commonly referred to as a subdirectory.
Directory files don't contain data in the user sense of data, they merely contain references to the files contained within them. It is perhaps noteworthy at this point to mention that any "file" that has files directly below contained within it in the hierarchy must be a directory, and any "file" that does not have files below it in the hierarchy can be an ordinary file, or a directory, albeit empty.
The third category of file mentioned above is a device file. This is another special file that is used to describe a physical device, such as a printer or a portable drive. This file contains no data whatsoever, it merely maps any data coming its way to the physical device it describes.
operating system - Unix Parent-child process relationship - Stack Overflow
However, not all of these file types may be present across various Unix implementations. File System Navigation To begin our discussion of navigating or moving around the file system, the concept of file names must be introduced. It is, after all, the name of a file that allows for its manipulation.
In simplest terms, a file name is a named descriptor for a file. However it is stongly advised that you use file names that are descriptive of the function of the file in question. By rule, Unix file names do not have to have ending extensions such as. However, certain applications with which you interact may require extensions, such as Adobe's Acrobat Reader.
And as always character case matters don't tell me you have forgotten this already? Thus the following are all valid Unix file names note these may be any file type: A file spec may simply consist of a file name, or it might also include more information about a file, such as where is resides in the overall file system.
There are 2 techniques for describing file specifications, absolute and relative. With absolute file specifications, the file specification always begins from the root directory, complete and unambiguous.
Absolute file specs are sometimes referred to as fully qualified path names 2. For example, the following are all absolute file specs from the diagram above: With relative file specifications, the file specification always is related to the users current position or location in the file system. Thus, the beginning left-most part of a relative file spec describes either: Beginning users often ask "How do I know where I am?
UNIX for Dummies Questions & Answers
As mentioned abpve, part of a relative file specification can be a reference to a parent directory. The way one references a parent of the current directory is with the characters. These characters with no separating spaces describe the parent directory relative to the current directory, again, one directory level up in the file system.
Note that more than one level up a parents parent, for example can be referenced with. The following are examples referencing the diagram above: To identify where we are, we type and the system returns the following: Moving about the file system is accomplished by using the cd command, which allows a user to change directories.
Remember, the file specification can always be a relative or an absolute specification. The shell with job control: The Bourne-again shell places the foreground job ps into its own process group The ps command is the process group leader and the only process in this process group. This process group is the foreground process group, since it has the controlling terminal. The login shell is a background process group while the ps command executes.8 Ways to Improve Parent Child Relationship
Both process groups, andare members of the same session. Executing this process in the background: The process group is no longer the foreground process group but a background process group. Executing two processes in a pipeline, as in: The login shell is the parent of both processes.
This is different from the Bourne shell, which created the last process cat1 in the pipeline first, and this process is the parent of first process ps. If we execute this pipeline in the background: The program that creates an orphaned process group is shown below: The child inherits the process group of its parent After fork, the parent sleeps for 5 seconds. This is our imperfect way of letting the child execute before the parent terminates. At this point, the child is a member of an orphaned process group: Another way of saying this is: If the process group is not orphaned, there is a chance that one of those parents in a different process group but in the same session will restart a stopped process in the process group that is not orphaned.
Here, the parent of every process in the group e. Since the process group is orphaned when the parent terminates, and the process group contains a stopped process, POSIX.
This causes the child to be continued, after processing the hang-up signal. The default action for the hang-up signal is to terminate the process, so we have to provide a signal handler to catch the signal. Note that the shell prompt appears with the output from the child, because two processes login shell and the child are writing to the terminal.
The parent process ID of the child has become 1.
- How Linux Process Life Cycle Works – Parent, Child, and Init Process
- UNIX: child processes upon parent termination
- The Unix File System
But for an orphaned process group, if the kernel were to stop it with this signal, the processes in the process group would probably never be continued.