From: Jann Horn <jann-XZ1E9jl8jIdeoWH0uzbU5w@public.gmane.org>
To: Cyrill Gorcunov <gorcunov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: "Michael Kerrisk (man-pages)"
<mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
"Iago López Galeiras"
<iago-973cpzSjLbNWk0Htik3J/w@public.gmane.org>,
"Andrey Vagin" <avagin-5HdwGun5lf+gSpxsJD1C4w@public.gmane.org>
Subject: Re: [PATCH] proc.5: document /proc/[pid]/task/[tid]/children
Date: Mon, 15 Aug 2016 00:45:46 +0200 [thread overview]
Message-ID: <20160814224546.GA32168@pc.thejh.net> (raw)
In-Reply-To: <20160814221359.GD1857-ZmlpmtaulQd+urZeOPWqwQ@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 3935 bytes --]
On Mon, Aug 15, 2016 at 01:13:59AM +0300, Cyrill Gorcunov wrote:
> On Sun, Aug 14, 2016 at 10:46:35PM +0200, Jann Horn wrote:
> > On Sun, Aug 14, 2016 at 11:14:41PM +0300, Cyrill Gorcunov wrote:
> > > On Sun, Aug 14, 2016 at 12:48:56PM +0200, Jann Horn wrote:
> > > > >
> > > > > Hi! First of all, sorry for delay. Guys, this is not really true. The same
> > > > > applies to plain "ls /proc".
> > > >
> > > > It does not. /proc is wobbly in a running system, /proc/$pid/children is
> > > > completely unreliable.
> > >
> > > Nope -- look into how pids are instantinated: once pids are read new ones
> > > may appear which you won't notice without re-read. You still may miss freshly
> > > created pids.
> >
> > That's pretty much inherent when you're inspecting a moving system - by the
> > time you've collected your information, it might be stale. So what?
>
> What "what"? I told you that the information you fetch from running system
> only valid when kernel does its work, once you jump back to userspace
> the information might not be valid anymore. And the @children does the
> same: in native procfs read you may miss freshly created processes,
> in @children read you may miss exited processes. It's the same nature.
"in @children read you may miss exited processes"? If that was the extent of it,
everything would be fine. But that's not what's happening. Read the comment in
get_children_pid():
* We might miss some children here if children
* are exited while we were not holding the lock,
* but it was never promised to be accurate that
* much.
*
* "Just suppose that the parent sleeps, but N children
* exit after we printed their tids. Now the slow paths
* skips N extra children, we miss N tasks." (c)
"skips N extra children". *NOT* necessarily the same N children that exited, but
also children that were running before you started reading the "children" file
and are still running afterwards.
That's the big difference between the interfaces: Normal procfs reads might not
return new or outdated information, which is mostly inherent when you're
inspecting a running system, but the "children" interface can also drop
information about completely stable task relationships.
> > > > I think these should work for obtaining a sufficiently consistent view
> > > > of the process structure of a running system.
> > > >
> > > > But yeah, safely using this interface isn't easy, and more
> > > > inode-centered APIs for interaction with processes would be nice to
> > > > have. (E.g. an entry in /proc/$pid that points to the parent inode,
> > > > maybe a directory containing entries that point to the child inodes,
> > > > and process directory entries offering functionality equivalent to
> > > > syscalls like kill(), sched_setscheduler() and prlimit().)
> > >
> > > Well, all this really waste a huge amount of time, that's why we needed
> > > $children. In general more preferred way might be task-diag interface
> > > which Andrew implemented (I'm not sure which exactly state of the
> > > series at the moment, have it been merged or not https://lkml.org/lkml/2016/4/11/932)
> >
> > Yuck. Everything is PID-based? That's ugly.
>
> That happened the process are pid based things.
PID-based interfaces suck unless you're the ptracer or reaper of all the
tasks you're inspecting, and an interface based on less reusable handles
(like procfs directory file descriptors or unique 64-bit identifiers or
whatever) would be much safer.
Yes, I know that all those traditional APIs use PIDs, but that doesn't
change that those interfaces suck. When you kill -9 a daemon that doesn't
quit when asked to quit, for example, there's a chance that the daemon
actually does quit and its PID is reallocated to some vital system
service just before you call kill() - and then your system breaks in
some unpleasant way.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-08-14 22:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-02 0:25 [PATCH] proc.5: document /proc/[pid]/task/[tid]/children Jann Horn
[not found] ` <b97bbf47-1180-0d32-ba08-1482020cc883@gmail.com>
[not found] ` <b97bbf47-1180-0d32-ba08-1482020cc883-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-03 22:52 ` Jann Horn
[not found] ` <20160803225254.GA14948-J1fxOzX/cBvk1uMJSBkQmQ@public.gmane.org>
2016-08-14 8:40 ` Cyrill Gorcunov
[not found] ` <20160814084026.GA1857-ZmlpmtaulQd+urZeOPWqwQ@public.gmane.org>
2016-08-14 10:48 ` Jann Horn
[not found] ` <20160814104856.GA12246-J1fxOzX/cBvk1uMJSBkQmQ@public.gmane.org>
2016-08-14 20:14 ` Cyrill Gorcunov
[not found] ` <20160814201441.GC1857-ZmlpmtaulQd+urZeOPWqwQ@public.gmane.org>
2016-08-14 20:46 ` Jann Horn
[not found] ` <20160814204635.GA2803-J1fxOzX/cBvk1uMJSBkQmQ@public.gmane.org>
2016-08-14 22:13 ` Cyrill Gorcunov
[not found] ` <20160814221359.GD1857-ZmlpmtaulQd+urZeOPWqwQ@public.gmane.org>
2016-08-14 22:45 ` Jann Horn [this message]
[not found] ` <20160814224546.GA32168-J1fxOzX/cBvk1uMJSBkQmQ@public.gmane.org>
2016-08-15 8:50 ` Cyrill Gorcunov
[not found] ` <20160815085004.GE1857-ZmlpmtaulQd+urZeOPWqwQ@public.gmane.org>
2016-08-15 11:53 ` Jann Horn
[not found] ` <20160815115333.GA11115-J1fxOzX/cBvk1uMJSBkQmQ@public.gmane.org>
2016-08-15 12:34 ` Cyrill Gorcunov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160814224546.GA32168@pc.thejh.net \
--to=jann-xz1e9jl8jideowh0uzbu5w@public.gmane.org \
--cc=avagin-5HdwGun5lf+gSpxsJD1C4w@public.gmane.org \
--cc=gorcunov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=iago-973cpzSjLbNWk0Htik3J/w@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).