xv6-examples-输出helloworld

任务:在控制台输出 "hello world"。

  • 使用 printf
  • 使用 forkwrite
  • 使用 dupwrite

使用 printf

helloworld.c

c 复制代码
#include "user/user.h"

int main(void){
    printf("hello world\n");
    return 0;
}

使用 forkwrite

helloworld2.c

c 复制代码
#include "user/user.h"

int main(void){
    int pid = fork();
    if (pid == 0) {
        write(1, "hello ", 6);
        exit(0);
    }else {
        wait(0);
        write(1, "world\n ", 6);
    }
    return 0;
}

使用 dupwrite

helloworld3.c

c 复制代码
#include "user/user.h"

int main(void){
    int fd = dup(1);
    write(1, "hello ", 6);
    write(fd, "world\n", 6);
    return 0;
}
相关推荐
深念Y2 天前
Fork 仓库瘦身指南:从 90MB 到 11MB
git·github·仓库·历史·瘦身·fork·上游
wunaiqiezixin7 天前
MIT 6.S081 xv6 源码精读(Scheduling):sched、scheduler
linux·unix·os·xv6·mit6.s081
wunaiqiezixin17 天前
MIT 6.S081 lazy 前置篇(lab5):缺页异常、惰性分配、写时复制、页面换出
linux·unix·os·xv6·mit6.s081
驱动探索者18 天前
RISC-V 指令集深度解析:从 ISA 到 Zephyr
网络·计算机·操作系统·os
TechEdu20260619 天前
[操作系统]操作系统文件系统与输入输出:架构、行为与调优
操作系统·计算机科学·os
无小道24 天前
深入理解 Linux 异步 I/O:从 epoll 到 io_uring
os
wunaiqiezixin25 天前
MIT 6.S081 syscall 实验篇(lab2):System call tracing (moderate)
linux·unix·os·xv6·mit6.s081
^yi1 个月前
【Linux系统编程】对操作系统的理解
linux·运维·服务器·操作系统·系统调用·os
星马梦缘2 个月前
操作系统计算题专项练习(15题)
操作系统·os·银行家算法·段页式