1UNSHARE(2)                 Linux Programmer's Manual                UNSHARE(2)
2
3
4

NAME

6       unshare - disassociate parts of the process execution context
7

SYNOPSIS

9       #define _GNU_SOURCE
10       #include <sched.h>
11
12       int unshare(int flags);
13

DESCRIPTION

15       unshare()  allows a process to disassociate parts of its execution con‐
16       text that are currently being shared with other processes.  Part of the
17       execution  context,  such  as the mount namespace, is shared implicitly
18       when a new process is created using fork(2) or  vfork(2),  while  other
19       parts,  such  as virtual memory, may be shared by explicit request when
20       creating a process using clone(2).
21
22       The main use of unshare() is to allow a process to control  its  shared
23       execution context without creating a new process.
24
25       The flags argument is a bit mask that specifies which parts of the exe‐
26       cution context should be unshared.  This argument is specified by ORing
27       together zero or more of the following constants:
28
29       CLONE_FILES
30              Reverse  the  effect  of the clone(2) CLONE_FILES flag.  Unshare
31              the file descriptor table, so that the calling process no longer
32              shares its file descriptors with any other process.
33
34       CLONE_FS
35              Reverse  the effect of the clone(2) CLONE_FS flag.  Unshare file
36              system attributes, so that the calling process no longer  shares
37              its  root directory, current directory, or umask attributes with
38              any other process.  chroot(2), chdir(2), or umask(2)
39
40       CLONE_NEWNS
41              This flag has the same effect as the clone(2) CLONE_NEWNS  flag.
42              Unshare  the  mount namespace, so that the calling process has a
43              private copy of its namespace which is not shared with any other
44              process.  Specifying this flag automatically implies CLONE_FS as
45              well.
46
47       If flags is specified as zero, then unshare() is a  no-op;  no  changes
48       are made to the calling process's execution context.
49

RETURN VALUE

51       On success, zero returned.  On failure, -1 is returned and errno is set
52       to indicate the error.
53

ERRORS

55       EINVAL An invalid bit was specified in flags.
56
57       ENOMEM Cannot allocate sufficient memory to copy parts of caller's con‐
58              text that need to be unshared.
59
60       EPERM  flags  specified  CLONE_NEWNS  but  the  calling process was not
61              privileged (did not have the CAP_SYS_ADMIN capability).
62

VERSIONS

64       The unshare() system call was added to Linux in kernel 2.6.16.
65

CONFORMING TO

67       The unshare() system call is Linux-specific.
68

NOTES

70       Not all of the process attributes that can be shared when a new process
71       is created using clone(2) can be unshared using unshare().  In particu‐
72       lar, as at kernel 2.6.16,  unshare()  does  not  implement  flags  that
73       reverse  the  effects of CLONE_SIGHAND, CLONE_SYSVSEM, CLONE_THREAD, or
74       CLONE_VM.  Such functionality may be added in the future, if required.
75

SEE ALSO

77       clone(2), fork(2), vfork(2), Documentation/unshare.txt
78

COLOPHON

80       This page is part of release 3.25 of the Linux  man-pages  project.   A
81       description  of  the project, and information about reporting bugs, can
82       be found at http://www.kernel.org/doc/man-pages/.
83
84
85
86Linux                             2008-11-20                        UNSHARE(2)
Impressum