Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

pid: add isolation between process visualization #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,7 @@ key msqid owner perms used-bytes messages

# no message queue results
```

## Process IDs

If you run `ps` inside of the container, you should not see the processes outside of it.
13 changes: 12 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ static int child_exec(void *stuff)
{
struct clone_args *args = (struct clone_args *)stuff;

if (umount("/proc", 0) != 0) {
fprintf(stderr, "failed to umount /proc %s\n", strerror(errno));
exit(-1);
}

if (mount("proc", "/proc", "proc", 0, "") != 0) {
fprintf(stderr, "failed to mount /proc %s\n", strerror(errno));
exit(-1);
}

const char *default_hostname = "containerhostname";

if (sethostname(default_hostname, strlen(default_hostname)) != 0) {
Expand All @@ -43,7 +53,8 @@ int main(int argc, char **argv)
struct clone_args args;
args.argv = &argv[1];

int clone_flags = CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWNET | SIGCHLD;
/* int clone_flags = CLONE_NEWPID | SIGCHLD; */
int clone_flags = CLONE_NEWPID | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWNET | SIGCHLD;

// this is the pid of the new process cloned
pid_t pid = clone(child_exec, child_stack + STACKSIZE, clone_flags, &args);
Expand Down