Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need some tips on implementing the chroot command in C

Tags:

c

chroot

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?

like image 682
anna karenina Avatar asked Mar 29 '26 23:03

anna karenina


1 Answers

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.

like image 116
phihag Avatar answered Apr 02 '26 13:04

phihag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!