summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2019-11-06 03:21:29 (GMT)
committerGitHub <noreply@github.com>2019-11-06 03:21:29 (GMT)
commit6c4c45efaeb40f4f837570f57d90a0b3429c6ae9 (patch)
tree4abd982b8454d295f7f0c16c2ab0ab94014ce584 /Modules/posixmodule.c
parent56698d57691af2272f695f8c17c835ed99545cde (diff)
downloadcpython-6c4c45efaeb40f4f837570f57d90a0b3429c6ae9.zip
cpython-6c4c45efaeb40f4f837570f57d90a0b3429c6ae9.tar.gz
cpython-6c4c45efaeb40f4f837570f57d90a0b3429c6ae9.tar.bz2
bpo-38692: Add os.pidfd_open. (GH-17063)
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 6d837c6..46cf7b2 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -7861,6 +7861,30 @@ os_wait_impl(PyObject *module)
}
#endif /* HAVE_WAIT */
+#if defined(__linux__) && defined(__NR_pidfd_open)
+/*[clinic input]
+os.pidfd_open
+ pid: pid_t
+ flags: unsigned_int = 0
+
+Return a file descriptor referring to the process *pid*.
+
+The descriptor can be used to perform process management without races and
+signals.
+[clinic start generated code]*/
+
+static PyObject *
+os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags)
+/*[clinic end generated code: output=5c7252698947dc41 input=c3fd99ce947ccfef]*/
+{
+ int fd = syscall(__NR_pidfd_open, pid, flags);
+ if (fd < 0) {
+ return posix_error();
+ }
+ return PyLong_FromLong(fd);
+}
+#endif
+
#if defined(HAVE_READLINK) || defined(MS_WINDOWS)
/*[clinic input]
@@ -13671,6 +13695,7 @@ static PyMethodDef posix_methods[] = {
OS_WAIT4_METHODDEF
OS_WAITID_METHODDEF
OS_WAITPID_METHODDEF
+ OS_PIDFD_OPEN_METHODDEF
OS_GETSID_METHODDEF
OS_SETSID_METHODDEF
OS_SETPGID_METHODDEF