#define _GNU_SOURCE /* See feature_test_macros(7) */
int setns(int fd, int nstype);
Given a file descriptor referring to a namespace, reassociate the call-
ing thread with that namespace.
The fd argument is a file descriptor referring to one of the namespace
entries in a /proc/[pid]/ns/ directory; see proc(5) for further infor-
mation on /proc/[pid]/ns/. The calling thread will be reassociated
with the corresponding namespace, subject to any constraints imposed by
the nstype argument.
The nstype argument specifies which type of namespace the calling
thread may be reassociated with. This argument can have one of the
0 Allow any type of namespace to be joined.
fd must refer to an IPC namespace.
fd must refer to a network namespace.
fd must refer to a UTS namespace.
Specifying nstype as 0 suffices if the caller knows (or does not care)
what type of namespace is referred to by fd. Specifying a nonzero
value for nstype is useful if the caller does not know what type of
namespace is referred to by fd and wants to ensure that the namespace
is of a particular type. (The caller might not know the type of the
namespace referred to by fd if the file descriptor was opened by
another process and, for example, passed to the caller via a UNIX
On success, setns() returns 0. On failure, -1 is returned and errno is
set to indicate the error.
EBADF fd is not a valid file descriptor.
EINVAL fd refers to a namespace whose type does not match that speci-
fied in nstype, or there is problem with reassociating the the
thread with the specified namespace.
ENOMEM Cannot allocate sufficient memory to change the specified names-
ated using clone(2) can be changed using setns().
The PID namespace and the mount namespace are not currently supported.
(See the descriptions of CLONE_NEWPID and CLONE_NEWNS in clone(2).)
clone(2), fork(2), vfork(2), proc(5), unix(7)
This page is part of release 3.35 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://man7.org/linux/man-pages/.
Linux 2011-10-04 SETNS(2)
Man Pages Copyright Respective Owners. Site Copyright (C) 1994 - 2017
All Rights Reserved.