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

NAME

6       unshare - disassociate parts of the process execution context
7

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

CONFORMING TO

63       The unshare() system call is Linux specific.
64

NOTES

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

SEE ALSO

75       clone(2), fork(2), vfork(2), Documentation/unshare.txt
76
77
78
79Linux 2.6.16                      2005-03-10                        UNSHARE(2)
Impressum