Hacker News new | ask | show | jobs
by inetknght 1878 days ago
> Why can’t Linux keep track of parent-child relationships and visualize them when you look at running processes?

Linux does keep track of parent-child process relationships. Linux, however, is just a kernel. It's not your operating system and it's definitely not your GUI.

I suggest you look at something like `htop`.

1 comments

It doesn’t. See below
It does. You're mistaking reparenting with another concept: the concept of an absolute parent PID.

The concept of an absolute parent PID is nonsensical. Having an absolute parent PID would reduce the maximum number of processes effectively infinitely by creating a linked list of parent IDs even if the original parent process is gone.

Imagine if PID 2 is a parent process. It spawns a child. The child spawns a child. That child spawns a child... all the way down to the maximum number of PIDs... the final child is PID n. Then, all of the intermediate processes exit.

The final child process with the maximum PID wants to look at its parent process... but it's gone. Now, what do you want the kernel to do?

Should the kernel tell you about that PID n-1? What if another process has been created and has inherited PID n-1? Does your check now think that the process's parent is still alive? Your check is incorrect and will lead to very aggrevating bugs. Should the kernel prevent PID n-1 from being reused? Congrats you've basically just reinvented zombie processes.

No. The solution is to just reparent PID n onto PID 1 and tell you that process is the parent now. Then you, as a developer, have to actually deal with an aspect of computer science: lifetime management of your objects processes. And the kernel is therefore more efficient for the vast majority of processes who don't need or care about their parent.