unshare --pid /bin/bash - fork cannot allocate memory

后端 未结 2 654
滥情空心
滥情空心 2020-12-14 02:54

I\'m experimenting with linux namespaces. Specifically the pid namespace.

I thought I\'d test something out with bash but run into this problem:

uns         


        
2条回答
  •  被撕碎了的回忆
    2020-12-14 03:12

    This does not explain why this happens, but shows how to correctly launch a shell in a new pid namespace:

    Use the -f flag to fork off the shell from unshare:

    unshare -fp /bin/bash
    

    You also need to pass the --mount-proc option to ensure that the shell will get PID 1 in the newly created namespace:

    unshare -fp --mount-proc /bin/bash
    

    Now run ps:

    # ps
       PID TTY          TIME CMD
     1 pts/1    00:00:00 bash
    11 pts/1    00:00:00 ps
    

提交回复
热议问题