0

I am trying to test the unshare command in Linux. I am using it to create a new user namespace. I tried the following test:

user1@myPC$ strace -e clone,unshare,fork,execve unshare --user
execve("/usr/bin/unshare", ["unshare", "--user"], [/* 71 vars */]) = 0
unshare(CLONE_NEWUSER)                  = 0
execve("/bin/bash", ["-bash"], [/* 71 vars */]) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9153
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9153, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9155
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9155, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9160
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9160, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9162
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9162, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9164
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9164, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0xb7275768) = 9167
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=9167, si_uid=65534, si_status=0, si_utime=0, si_stime=0} ---
nobody@MyPC:~$

I want to ask why are there so many calls to clone() made ?

  • 1
    All of them are after execve(/bin/bash), so it's bash doing them, not unshare. It's probably fork()ing when running the commands from ~/.bashrc. – mosvy Apr 10 at 22:11
4

unshare(1) is not calling clone(2) at all. After calling the unshare(CLONE_NEWUSER) system call, the unshare program is exec'ing through to the program given on the command line or the program from the $SHELL environment variable.

In your case, that's bash, which is fork-ing a lot (fork(2) is a wrapper for clone(2) nowadays) while processing the commands from its initialization scripts (~/.bashrc, etc).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.