xv6-examples-输出helloworld

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

  • 使用 printf
  • 使用 fork 和 write
  • 使用 dup 和 write

使用 printf

helloworld.c

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

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

使用 fork 和 write

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;
}

使用 dup 和 write

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;
}
相关推荐
wunaiqiezixin2 天前
MIT 6.S081 util 实验篇(lab1):primes (moderate/hard)
linux·unix·os·xv6·mit6.s081
半仙白桑20 天前
内核篇第一讲:linux创建进程
linux·fork·创建进程
wunaiqiezixin21 天前
MIT 6.S081 file system 实验篇(lab9):Large files (moderate)
linux·unix·os·xv6·mit6.s081
TechEdu2026061 个月前
[操作系统]操作系统04:进程间通信(IPC)-机制、模式与实践
操作系统·os
消失的旧时光-19431 个月前
Android 系统层扫盲 05:Android 开机后发生了什么?从 Bootloader 到 Launcher
android·zygote·fork·aosp·cow
深念Y1 个月前
Fork 仓库瘦身指南:从 90MB 到 11MB
git·github·仓库·历史·瘦身·fork·上游
wunaiqiezixin2 个月前
MIT 6.S081 xv6 源码精读(Scheduling):sched、scheduler
linux·unix·os·xv6·mit6.s081
wunaiqiezixin2 个月前
MIT 6.S081 lazy 前置篇(lab5):缺页异常、惰性分配、写时复制、页面换出
linux·unix·os·xv6·mit6.s081
驱动探索者2 个月前
RISC-V 指令集深度解析:从 ISA 到 Zephyr
网络·计算机·操作系统·os
TechEdu2026062 个月前
[操作系统]操作系统文件系统与输入输出:架构、行为与调优
操作系统·计算机科学·os