From: Alejandro Colomar <alx@kernel.org>
To: Emanuele Torre <torreemanuele6@gmail.com>
Cc: linux-man@vger.kernel.org
Subject: Re: [man-pages] pidfd_send_signal(2) innacurately describes how to get a pidfd
Date: Fri, 25 Aug 2023 19:58:34 +0200 [thread overview]
Message-ID: <6e7c44a4-18b3-89d8-709e-5d01dbc9b3d7@kernel.org> (raw)
In-Reply-To: <ZOfm0VZha-CLDYgX@t420>
[-- Attachment #1.1: Type: text/plain, Size: 2138 bytes --]
Hi Emanuele,
On 2023-08-25 01:25, Emanuele Torre wrote:
> Hi.
>
> Today, I was reading pidfd_send_signal(2), and I was suprised to see it
> mentioning that you can get a PID file descriptor by opening a /proc/pid
> directory.
>
> NOTES
> PID file descriptors
> The pidfd argument is a PID file descriptor, a file descriptor
> that refers to process. Such a file descriptor can be obtained
> in any of the following ways:
> . by opening a /proc/pid directory;
> . using pidfd_open(2); or
> . via the PID file descriptor that is returned by a call to
> clone(2) or clone3(2) that specifies the CLONE_PIDFD flag.
>
> Unfortunately, if you open /proc/123, you don't get a pidfd for the
> process with pid 123; as expected, you will just get a directory file
> descriptor for /proc/123.
>
> And that directory file descriptor won't be usable as a PID file
> descriptor either.
> (openpidfd, and pidfdgetfd are just simple wrappers for pidfd_open, and
> pidfd_getfd)
>
> $ pidfdgetfd 9 0 0 echo hello 9</proc/1584616
> pidfd_getfd: Bad file descriptor
> $ # you must use pidfd_open
> $ openpidfd 9 1584616 pidfdgetfd 9 0 0 echo hello
> hello
>
> I also wrote a test program that uses a /proc/pid directory file
> descriptor as pidfd for waitid(P_PID) and that also didnd't work
> (waitid fails with EINVAL).
>
> But those directory file descriptors do work as alternative to actual
> pidfds for pidfd_send_signal(2) specifically.
>
> I think the documentation should be changed to say that
> pidfd_send_signal accepts either a PID file descriptor (obtainable using
> pidfd_open or CLONE_PIDFD), or, alternatively, a file descriptor for a
> /proc/pid directory to avoid confusions.
Would you mind sending a patch? If you do, please include in the commit
message the source code _and_ the execution of all of the programs you
mentioned above.
Thanks,
Alex
>
> Thank you.
>
> o/
> emanuele6
--
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2023-08-25 17:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-24 23:25 [man-pages] pidfd_send_signal(2) innacurately describes how to get a pidfd Emanuele Torre
2023-08-25 17:58 ` Alejandro Colomar [this message]
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=6e7c44a4-18b3-89d8-709e-5d01dbc9b3d7@kernel.org \
--to=alx@kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=torreemanuele6@gmail.com \
/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).