Live data from Hacker News

Killing a process and all of its descendants

morningcoffee.io

21–30 of 76 posts

Re: Killing a process and all of its descendants

#21
post #20

Earlier quoted context omitted.

Unfortunately, as Linux has matured, many of its developers refuse to adapt technologies for the sole reason that it "stinks" of Microsoft. Cutler and his team were pretty forward thinking given that NT is over 30 years old. See also: the async i/o headaches and the inability to WaitForSingleObject()/WaitForMultipleObjects() (or an analogue) in Linux. It's a shame really.

re: WaitForMultipleObjects, finally something like that is likely coming to Linux: https://www.reddit.com/r/linux/comments/ck77gm/valve_propose... > It's a shame really. Well, yes, and of course, yet at the same time it's FOSS, so ... if someone really needed it, they should have proposed a patch. ¯\_(ツ)_/¯

> Well, yes, and of course, yet at the same time it's FOSS, so ... if someone really needed it, they should have proposed a patch. ¯\_(ツ)_/¯

It's a bit like doing I/O that doesn't throw your data away... just use O_DIRECT, bring your own I/O manager and page cache and scheduling and simply implement all the low-level compatibility stuff yourself if you need such a weird thing ¯\_(ツ)_/¯

Re: Killing a process and all of its descendants

#23
post #14

Earlier quoted context omitted.

> Beyond the ability to unambiguously specify which process should be waited for, this change will eventually enable another interesting feature: it will make it possible to wait for a process that is not a child — something that waitid() cannot do now. Since a pidfd is a file descriptor, it can be passed to another process via an SCM_RIGHTS datagram in the usual manner. The recipient of a pidfd will, once this funct…

Perhaps pidfd_open(pid, ...)? https://lwn.net/Articles/789023/ I find it bizarre they called it "pidfd_" rather than just "process_" or "proc_"... almost seems like they deliberately avoided the obvious?

What obvious? The command creates and returns a pidfd for the pid passed, not a process or a proc (which would be conflated with other concepts in Linux).

Re: Killing a process and all of its descendants

#25
post #13
post #9

Earlier quoted context omitted.

That's definitely the correct way to do this today. But even then `kill -9 $(< /sys/fs/cgroup/systemd/tasks)` is not enough if your goal is to reliably kill all processes because that's not atomic. Instead you'll have to freeze all processes, send SIGKILL and then unfreeze.

Can freezing be done atomically?

I think the freezer cgroup does this, but I do t think systemd uses it.

Re: Killing a process and all of its descendants

#26
post #7
post #5

Earlier quoted context omitted.

Not anymore: b53b0b9d9a613c418057f6cb921c2f40a6f78c24 (pidfd: add polling support)

Wow, finally! Committed just 3 months ago. Might be able to finally rely on it in Linux distros a few years from now! https://github.com/torvalds/linux/commit/b53b0b9d9a613c41805...

It's in kernel v5.3, which is expected in September, so it might be in Ubuntu Eoan Ermine 19.10. (After all 5.0 got released in March and Ubuntu 19.04 ships with 5.0.)

Re: Killing a process and all of its descendants

#27
post #3

This is why cgroups were invented. They solve this problem. Start a process in its own cgroup, and you can later confidently kill the process and all of its descendants. Container "technologies" use cgroups extensively, as does systemd service management.

systemd uses cgroups, correct? just wondering what the options are for learning more about this, would it be enough, assuming you'd only be working with systemd operating systems, to learn the systemd concepts of slices etc.?

Re: Killing a process and all of its descendants

#28

The GNU coreutils timeout command encapsulates a lot of these issues. It's surprisingly difficult to handle all the edge cases and races. https://www.maizure.org/projects/decoded-gnu-coreutils/timeo...

Cool. Anyone know how they make diagrams like those?

Re: Killing a process and all of its descendants

#29

The GNU coreutils timeout command encapsulates a lot of these issues. It's surprisingly difficult to handle all the edge cases and races. https://www.maizure.org/projects/decoded-gnu-coreutils/timeo...

Cool. Anyone know how they make diagrams like those?

I was curious as well. According to the author, "All the diagrams were hand-crafted in PowerPoint."

https://github.com/MaiZure/coreutils-8.3/issues/1#issuecomme...

Re: Killing a process and all of its descendants

#30
post #22
post #2

Even waiting for a process to exit is surprisingly hard (impossible?) in Linux, unless it's your child.

Is it any easier on any other platform? Genuinely asking.

Windows NT has had “kill process tree” since as far back as I recall (mid 1990s). See:

  taskkill /t
Post reply on HN