Cần giúp về C, Mini Shell

Mình tạo cái Mini Shell để nhận lênh cơ bản (ls,cd) nhưng đến khi làm cái clone(), (sub-shell) thì lại không biết làm sao. Mấy bạn nào rành chi mình với !!

The options for different containers can be added together in a clone() or clone2() call. Here are some of the options:

  • CLONE_NEWIPC - New namespace for IPC
  • CLONE_NEWUTS - Setup new hostname and domain
  • CLONE_NEWUSER - User and group changes
  • CLONE_NEWNET - New network namespace
  • CLONE_NEWNS - New mount namespace

Once in your “sub-shell” you will test the clone options with the following commands (as examples):

CLONE_NEWNET
sh-4.1# ip link

CLONE_NEWNS
sh-4.1# readlink /proc/[your process id]/ns/mnt
E.g. if your PID is 2324, then the command would be
readlink /proc/2324/ns/mnt

You can find your process ID with the ‘ps’ command (look for your shell name) as in:
sh-4.1# ps
PID TTY TIME CMD
2249 pts/1 00:00:00 bash // This is my default
4381 pts/1 00:00:00 sh // This is my sub-shell - to test clone
5236 pts/1 00:00:00 ps
sh-4.1#

CLONE_NEWIPC / CLONE_NEWUSER / CLONE_NEWUTS
All of these clone arguments can be seen by looking in the /proc directory.

Look under /proc/$$/ns/* for the filename (number). Note it change when you pass in one of the arguments above for IPC/USER/UTS.

NOTE: In the shell, the $$ will print out your Process ID (PID)

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?