@@ -571,21 +571,23 @@ process and user.
571
571
572
572
.. function :: setns(fd, nstype=0)
573
573
574
- Reassociate thread with a namespace, see the :manpage: `setns(2)` man page for more details.
574
+ Reassociate the current with a namespace.
575
+ See the :manpage: `setns(2)` man page for more details.
575
576
576
577
If *fd * refers to a ``/proc/[pid]/ns/ `` link, ``setns() `` reassociates the
577
578
calling thread with the namespace associated with that link, subject to any
578
- constraints imposed by the *nstype * argument (or any if ``0 ``).
579
+ constraints imposed by the *nstype * argument (a *nstype * of ``0 `` means no
580
+ constraints).
579
581
Since Linux 5.8, *fd * may refer to a PID file descriptor obtained from
580
582
:func: `~os.pidfd_open `. In this case ``setns() `` reassociates the calling thread
581
583
into one or more of the same namespaces as the thread referred to by *fd *
582
- subject to any constraints imposed by the *nstype *, which is
583
- a bit mask specified by combining one or more of the ``CLONE_NEW* `` constants,
584
- e.g. ``setns(fd, os.CLONE_NEWUTS | os.CLONE_NEWPID) ``.
585
- The callers memberships in unspecified namespaces are left unchanged.
584
+ subject to any constraints imposed by *nstype *, which is a bit mask specified
585
+ by combining one or more of the ``CLONE_NEW* `` constants,
586
+ e.g., as ``setns(fd, os.CLONE_NEWUTS | os.CLONE_NEWPID) ``.
587
+ The caller's memberships in unspecified namespaces are left unchanged.
586
588
*fd * can be any object with a :meth: `fileno ` method, or a raw file descriptor.
587
589
588
- This example reassociates the thread with the ``init `` process' network namespace::
590
+ This example reassociates the thread with the ``init `` process's network namespace::
589
591
590
592
fd = os.open("/proc/1/ns/net", os.O_RDONLY)
591
593
os.setns(fd, os.CLONE_NEWNET)
@@ -595,6 +597,10 @@ process and user.
595
597
596
598
.. versionadded :: 3.12
597
599
600
+ .. seealso ::
601
+
602
+ The :func: `~os.unshare ` function.
603
+
598
604
.. function :: setpgrp()
599
605
600
606
Call the system call :c:func: `setpgrp ` or ``setpgrp(0, 0) `` depending on
@@ -760,12 +766,15 @@ process and user.
760
766
761
767
.. function :: unshare(flags)
762
768
763
- Disassociate parts of the process execution context, see the :manpage: `unshare(2)`
769
+ Disassociate parts of the process execution context, and move them into a
770
+ newly created namespace.
771
+ See the :manpage: `unshare(2)`
764
772
man page for more details.
765
773
The *flags * argument is a bit mask combining zero or more of the ``CLONE_* ``
766
774
constants using ``| `` (bitwise or), that specifies which parts of the execution
767
- context should be unshared.
768
- If *flags * is specified as zero, no changes are made to the calling process'
775
+ context should be unshared from their existing associations and moved to a
776
+ new namespace..
777
+ If *flags * is specified as zero, no changes are made to the calling process's
769
778
execution context.
770
779
771
780
.. availability :: Linux 2.6.16 or newer.
0 commit comments