任务:xv6-lab-utilities
实验一:
sleep函数
过程:在user目录下创建sleep.c,仿照其它程序,写出sleep调用的结构。
#include "kernel/types.h"
#include "user/user.h"
int main(int argc, char *argv[]) {
if (argc != 2)
write(2, "Error message", strlen("Error message"));
int x = atoi(argv[1]);
sleep(x);
exit();
}
添加到Makefile文件中的uprogs中
UPROGS=\
$U/_sleep\
实验二 pingpong
同上
#include "kernel/types.h"
#include "user/user.h"
int main(int argc, char *argv[]) {
int parent_fd[2], child_fd[2];
pipe(parent_fd);
pipe(child_fd);
char buf[64];
if (fork()) {
// Parent
write(parent_fd[1], "ping", strlen("ping"));
read(child_fd[0], buf, 4);
printf("%d: received %s\n", getpid(), buf);
} else {
// Child
read(parent_fd[0], buf, 4);
printf("%d: received %s\n", getpid(), buf);
write(child_fd[1], "pong", strlen("pong"));
}
exit();
}
UPROGS=\
$U/_pingpong\
这篇博客详细介绍了如何在XV6操作系统中进行实验,包括实现sleep函数以及pingpong程序的步骤。首先,用户需要在user目录下创建并编写sleep.c,参照其他程序结构。接着,将sleep程序添加到Makefile的uprogs列表中,确保能成功编译。实验二则延续了这一过程,继续深化对操作系统内核的理解。
1649

被折叠的 条评论
为什么被折叠?



