diff options
Diffstat (limited to 'man2/clone.2')
-rw-r--r-- | man2/clone.2 | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/man2/clone.2 b/man2/clone.2 index ec43841eb..4c5b4ac6b 100644 --- a/man2/clone.2 +++ b/man2/clone.2 @@ -1788,9 +1788,9 @@ To get the truth, it was sometimes necessary to use code such as the following: .in +4n .EX #include <syscall.h> - +\& pid_t mypid; - +\& mypid = syscall(SYS_getpid); .EE .in @@ -1848,34 +1848,34 @@ so we should include it for portability. #include <sys/utsname.h> #include <sys/wait.h> #include <unistd.h> - +\& static int /* Start function for cloned child */ childFunc(void *arg) { struct utsname uts; - +\& /* Change hostname in UTS namespace of child. */ - +\& if (sethostname(arg, strlen(arg)) == \-1) err(EXIT_FAILURE, "sethostname"); - +\& /* Retrieve and display hostname. */ - +\& if (uname(&uts) == \-1) err(EXIT_FAILURE, "uname"); printf("uts.nodename in child: %s\en", uts.nodename); - +\& /* Keep the namespace open for a while, by sleeping. This allows some experimentation\-\-for example, another process might join the namespace. */ - +\& sleep(200); - +\& return 0; /* Child terminates now */ } - +\& #define STACK_SIZE (1024 * 1024) /* Stack size for cloned child */ - +\& int main(int argc, char *argv[]) { @@ -1883,44 +1883,44 @@ main(int argc, char *argv[]) char *stackTop; /* End of stack buffer */ pid_t pid; struct utsname uts; - +\& if (argc < 2) { fprintf(stderr, "Usage: %s <child\-hostname>\en", argv[0]); exit(EXIT_SUCCESS); } - +\& /* Allocate memory to be used for the stack of the child. */ - +\& stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, \-1, 0); if (stack == MAP_FAILED) err(EXIT_FAILURE, "mmap"); - +\& stackTop = stack + STACK_SIZE; /* Assume stack grows downward */ - +\& /* Create child that has its own UTS namespace; child commences execution in childFunc(). */ - +\& pid = clone(childFunc, stackTop, CLONE_NEWUTS | SIGCHLD, argv[1]); if (pid == \-1) err(EXIT_FAILURE, "clone"); printf("clone() returned %jd\en", (intmax_t) pid); - +\& /* Parent falls through to here */ - +\& sleep(1); /* Give child time to change its hostname */ - +\& /* Display hostname in parent\[aq]s UTS namespace. This will be different from hostname in child\[aq]s UTS namespace. */ - +\& if (uname(&uts) == \-1) err(EXIT_FAILURE, "uname"); printf("uts.nodename in parent: %s\en", uts.nodename); - +\& if (waitpid(pid, NULL, 0) == \-1) /* Wait for child */ err(EXIT_FAILURE, "waitpid"); printf("child has terminated\en"); - +\& exit(EXIT_SUCCESS); } .EE |