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;
}
相关推荐
无小道4 天前
深入理解 Linux 异步 I/O:从 epoll 到 io_uring
os
wunaiqiezixin5 天前
MIT 6.S081 syscall 实验篇(lab2):System call tracing (moderate)
linux·unix·os·xv6·mit6.s081
^yi14 天前
【Linux系统编程】对操作系统的理解
linux·运维·服务器·操作系统·系统调用·os
星马梦缘1 个月前
操作系统计算题专项练习(15题)
操作系统·os·银行家算法·段页式
阿pin1 个月前
Android随笔-Zygote中fork究竟是什么?
android·zygote·fork
白狐_7982 个月前
【XV6操作系统】Lab2(Page Table) 满分通关与答辩指南:结合408考点深度剖析
操作系统·麒麟·xv6
Irissgwe3 个月前
四、进程控制(进程创建与终止)
linux·c++·进程·系统编程·fork·进程创建·进程终止
程序猿多布3 个月前
Fork操作笔记
git·fork
岑梓铭3 个月前
考研408《操作系统》复习笔记,第二章《2.3.3 + 2.3.4 经典同步问题、管程》
笔记·考研·操作系统·408·os