init commit of lab3_challenge1

lab3_challenge1_wait
Zhiyuan Shao 2 years ago
parent 448d994bba
commit 18ef8d77b8

@ -4,8 +4,10 @@ Copyright License
The PKE software is: The PKE software is:
Copyright (c) 2021, Zhiyuan Shao (zyshao@hust.edu.cn), Copyright (c) 2021, Zhiyuan Shao (zyshao@hust.edu.cn),
Yi Gui (gy163email@163.com), Ziming Yuan (1223962053@qq.com),
Yan Jiao (773709579@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 Huazhong University of Science and Technology
Permission is hereby granted, free of charge, to any person obtaining Permission is hereby granted, free of charge, to any person obtaining

@ -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------------------------ #------------------------targets------------------------
$(OBJ_DIR): $(OBJ_DIR):
@-mkdir -p $(OBJ_DIR) @-mkdir -p $(OBJ_DIR)

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

@ -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;
}
Loading…
Cancel
Save