我知道在linux中使用命令“chroot”需要一些文件或目录,例如usr
,bin
等等。但是当我chroot()
在 C 中使用该函数时,我需要这些文件吗?
这是我的代码,其中“hw.out”是一个二进制文件,只打印“Hello, world”。我编译它并以root身份运行它,但它无法打印“Hello,world”。我还应该做什么?谢谢!
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int result = chroot(".");
if(result == 0)
printf("Chroot Succese.\n");
char *arrays[]={"./hw.out",NULL};
execvp("./hw.out", arrays);
return 0;
}