C
C
cypok2011-07-02 20:38:18
*nix-like systems
cypok, 2011-07-02 20:38:18

Why is the process hierarchy needed in Unix?

I am currently reading Andrew Tanenbaum's Modern Operating Systems.
It is not entirely clear why Unix maintains a hierarchy of processes? Tanenbaum writes the following, but I still don't understand their role:

In UNIX, a process, all of its child processes, and more distant children form a process group. When the user sends a signal from the keyboard, it reaches all the members of that process group currently associated with the keyboard (typically all running processes that were created in the current window). Each process individually can capture the signal, ignore it, or take a default action that should be killed by the signal.
As another example of the role played by the process hierarchy, let's look at how UNIX initializes itself at startup. The boot image has a special process called init. At the beginning of its work, it reads a file reporting the number of terminals. It then forks, spawning one process per terminal. These processes wait until someone logs into the system. If the registration succeeds, the registration process spawns a shell to accept commands. These commands can spawn other processes, and so on. Thus, all processes in the entire system belong to a single tree, at the root of which is the init process.

If someone can explain popularly - I will be very grateful.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
Z
Zigmar, 2011-07-03
@cypok

I think the question “why” is not entirely correct here, I think this is just a property that is a direct consequence of the system architecture. I'm not sure where the Unix designers came from, but it seems to me that it's not from "let's make a process tree", but "how we will implement the creation and management of processes." The fact is that in Unix, processes, except for init, are not created just like that, “out of thin air”, they always branch off from another process (fork) and as a result, two processes are obtained from one process - parent and child between which there is a close connection ( and as a consequence naturally obtaining a tree structure). In addition to the signals already mentioned, the child process inherits file descriptors, through which, if necessary, communication is established between the child and the parent process.

O
odessky, 2011-07-02
@odessky

So that when the parent is killed, all child ones are automatically closed. And by graceful all the subsidiaries died, but the parent one remained. See Apache for example.

K
ksusha, 2011-07-03
@ksusha

Просто в Unix'е очень многое завязано на иерархии процессов, что и демонстрируют приведенные в цитате примеры.
Вот еще примерчик, где используется иерархия.
Когда процесс умирает, его родитель оповещается об этом. После этого он (родитель) удаляет из таблицы дескриптор умершего дочернего процесса. Если у процесса нет родителя, то этот дескриптор без перезагрузки ОС из памяти уже не удалить. Это расходует память. Дескриптор процесса весит не так чтобы уж очень мало — ~ 1,7 Кб.
Если родитель умер раньше дочки, то родитель переназначается, часто это бывает как раз init, который периодически запрашивает информацию о своих потомках и убивает их дескрипторы.
Another implementation of threads (in Linux, at least, where there is no explicit support for threads) is tied to the connection of processes with each other. When a child is spawned by a parent, flags indicate which resources to fumble between them. Plus, the child process inherits a lot of properties from the parent, such as UID, so the process starts with the same privileges as the parent.
If there were no hierarchy, all of the above would have to be implemented somehow differently, but in Unix it is, just a feature of the architecture, as Zigmar wrote.

M
MrSteve, 2011-07-03
@MrSteve

In the same section, Tanenbaum writes about the reincarnation server. It is responsible for starting servers and drivers. Thus, all servers and drivers are children of the reincarnation server. When one of the child processes terminates, the reincarnation server is notified of this and can start it again. Here is one example of using process hierarchy

E
Eldar Musin, 2011-07-02
@eldarmusin

The meaning lies precisely in the communications between processes. As he describes, but I agree that he does not say directly what it is for.
In fact, with the help of the hierarchy, it is possible to capture all processes via init .
If there were no hierarchy, then the broadcast of system signals might not concern everyone.
Then, in the very process that it sends, you can specify at what level it should be listened to.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question