From 18ef8d77b81d5ffa60a24e1c5fa8979c65698847 Mon Sep 17 00:00:00 2001 From: Zhiyuan Shao Date: Mon, 8 May 2023 15:30:33 +0800 Subject: [PATCH] init commit of lab3_challenge1 --- LICENSE.txt | 6 ++++-- Makefile | 2 +- user/app_two_long_loops.c | 28 ---------------------------- user/app_wait.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 31 deletions(-) delete mode 100644 user/app_two_long_loops.c create mode 100644 user/app_wait.c diff --git a/LICENSE.txt b/LICENSE.txt index ffe4849..0aba838 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -4,8 +4,10 @@ Copyright License The PKE software is: Copyright (c) 2021, Zhiyuan Shao (zyshao@hust.edu.cn), - Yi Gui (gy163email@163.com), - Yan Jiao (773709579@qq.com), + Ziming Yuan (1223962053@qq.com), + Yixin Song (yixinsong@hust.edu.cn), + Boyang Li (liboyang_hust@163.com), + Wenzhuo Liu (mgt@oi-wiki.org) Huazhong University of Science and Technology Permission is hereby granted, free of charge, to any person obtaining diff --git a/Makefile b/Makefile index 2dde5bf..598a3e3 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,7 @@ USER_OBJS := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(USER_CPPS))) -USER_TARGET := $(OBJ_DIR)/app_two_long_loops +USER_TARGET := $(OBJ_DIR)/app_wait #------------------------targets------------------------ $(OBJ_DIR): @-mkdir -p $(OBJ_DIR) diff --git a/user/app_two_long_loops.c b/user/app_two_long_loops.c deleted file mode 100644 index 2568485..0000000 --- a/user/app_two_long_loops.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * The application of lab3_3. - * parent and child processes never give up their processor during execution. - */ - -#include "user/user_lib.h" -#include "util/types.h" - -int main(void) { - uint64 pid = fork(); - uint64 rounds = 100000000; - uint64 interval = 10000000; - uint64 a = 0; - if (pid == 0) { - printu("Child: Hello world! \n"); - for (uint64 i = 0; i < rounds; ++i) { - if (i % interval == 0) printu("Child running %ld \n", i); - } - } else { - printu("Parent: Hello world! \n"); - for (uint64 i = 0; i < rounds; ++i) { - if (i % interval == 0) printu("Parent running %ld \n", i); - } - } - - exit(0); - return 0; -} diff --git a/user/app_wait.c b/user/app_wait.c new file mode 100644 index 0000000..eeea575 --- /dev/null +++ b/user/app_wait.c @@ -0,0 +1,31 @@ +/* + * This app fork a child process, and the child process fork a grandchild process. + * every process waits for its own child exit then prints. + * Three processes also write their own global variables "flag" + * to different values. + */ + +#include "user/user_lib.h" +#include "util/types.h" + +int flag; +int main(void) { + flag = 0; + int pid = fork(); + if (pid == 0) { + flag = 1; + pid = fork(); + if (pid == 0) { + flag = 2; + printu("Grandchild process end, flag = %d.\n", flag); + } else { + wait(pid); + printu("Child process end, flag = %d.\n", flag); + } + } else { + wait(-1); + printu("Parent process end, flag = %d.\n", flag); + } + exit(0); + return 0; +}