Search code examples
cchroot

I need some tips on implementing the chroot command in C


I am tasked with writing a simple shell along with these three commands: "nl", "head", "chroot"(with no parameters). I've written nl.c and head.c but I don't know where to start with the chroot.c. I've read what chroot does, googled some documentation and to me as a beginner this is complicated.

Any advice on this matter?


Solution

  • chroot without an argument just prints an error message. You can use printf for that.

    Otherwise, chroot calls chroot, chdir("/") and then executes a shell with one of the exec* functions.