[Chapter 6] Parent-Child Relationships
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. Fork() calls are scattered throughout UNIX®/Linux® code. fork00a The original process is called the parent, and the child is a near-exact copy of the parent. 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.
The operating system kernel identifies each process by its process identifier. Process 0 is a special process that is created when the system boots; after forking a child process process 1process 0 becomes the swapper process sometimes also known as the " idle task ".
Process 1, known as initis the ancestor of every other process in the system. Parent is the process that receives the SIGCHLD signal on child's termination, whereas real parent is the thread that actually created this child process in a multithreaded environment. For a normal process, both these two values are same, but for a POSIX thread which acts as a process, these two values may be different. Zombie process The operating system maintains a table that associates every process, by means of its process identifier generally referred to as "pid" to the data necessary for its functioning.Fork() system call tutorial
During a process's lifetime, such data might include memory segments designated to the process, the arguments it's been invoked with, environment variables, counters about resource usage, user-id, group-id and group set, and maybe other types of information. When a process terminates its execution, either by calling exit even if implicitly, by executing a return command from the main function or by receiving a signal that causes it to terminate abruptly, the operating system releases most of the resources and information related to that process, but still keeps the data about resource utilization and the termination status code, because a parent process might be interested in knowing if that child executed successfully by using standard functions to decode the termination status code and the amount of system resources it consumed during its execution.
By default, the system assumes that the parent process is indeed interested in such information at the time of the child's termination, and thus sends the parent the signal SIGCHLD to alert that there is some data about a child to be collected.
Such collection is done by calling a function of the wait family either wait itself or one of its relatives, such as waitpid, waitid or wait4. As soon as this collection is made, the system releases those last bits of information about the child process and removes its pid from the process table.
However, if the parent process lingers in collecting the child's data or fails to do it at allthe system has no option but keep the child's pid and termination data in the process table indefinitely. Such a terminated process whose data has not been collected is called a zombie process, or simply a zombie, in the UNIX parlance. The name is a humorous analogy due to considering terminated process as "no longer alive" or "dead"—since it has really ceased functioning—and a lingering dead process still "incarnated" in the "world of the living" processes—the process table—which is therefore actually "undead", or "zombie".
Zombie processes might pose problems on systems with limited resources or that have limited-size process tables, as the creation of new, active processes might be prevented by the lack of resources still used by long lasting zombies. Since all data is essentially a stream of bytes, each device can be viewed logically as a file.
All files in the Unix file system can be loosely categorized into 3 types, specifically: The first type of file listed above is an ordinary file, that is, a file with no "special-ness". Ordinary files are comprised of streams of data bytes stored on some physical device.
Examples of ordinary files include simple text files, application data files, files containing high-level source code, executable text files, and binary image files. Note that unlike some other OS implementations, files do not have to be binary Images to be executable more on this to come. 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. 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.
The fork() call: POSIX Processes and Parent-Child Relationships - Lynx Software Technologies
Thus, the beginning left-most part of a relative file spec describes either: Beginning users often ask "How do I know where I am? 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. As before, we type and the system returns the following: The simple and open ended answer is "it depends. This also depends upon how long the file specification is, or how easy it is to type, including any special characters, or how familiar one is with the current location in the file system hierarchy, etc.
Take some time to navigate the file system of your Unix implementation and see how it compares to the diagram above. More information can be found by searching on fully qualified path names in your favorite search engine. Additional File Attributes As was learned in the Getting Starting section, to determine or see what files are in our current working directory, we use the ls command.
This command allows the user to simply list their files. From the above output, we can observe 7 attribute fields listed for each file. From right to left, the attribute fields are: If the file has not been modified within the last year or six months for Linuxthe year of last modification is displayed.
Note also if the file is a directory, this is the size of the structure needed to manage the directory hierarchy.