forked from Azure-stars/Starry
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Arceos-monolithic/zlm_1_6
Zlm 第一阶段任务六(杨金全)
- Loading branch information
Showing
9 changed files
with
122 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ make run | |
```shell | ||
# 构建镜像 | ||
./build_img.sh sdcard | ||
|
||
# 运行 Unikernel 架构内核 | ||
make run | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <signal.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
// // #define WEXITSTATUS(s) (((s)&0xff00) >> 8) | ||
// // #define WIFEXITED(s) (!WTERMSIG(s)) | ||
// #define WIFEXITED(s) ((s)&0x7f) | ||
|
||
int main(void) | ||
{ | ||
pid_t pid, wpid; | ||
int status; | ||
int i = 0; | ||
pid = fork(); | ||
// printf(" %d \n", pid); | ||
if (pid == -1) { | ||
// fork失败 | ||
perror("fork failed"); | ||
exit(EXIT_FAILURE); | ||
} else if (pid == 0) { //子进程 | ||
printf("Child --- My Parent is %d\n", getppid()); | ||
sleep(5); | ||
// 子进程的任务完成,现在退出 | ||
printf("Child Process is exiting\n"); | ||
exit(9); // 退出子进程 | ||
} else if(pid > 0) { //父进程 | ||
wpid = wait(&status); //等待回收子进程 | ||
|
||
printf("Status %d\n", status); | ||
|
||
if(wpid == -1) { | ||
perror("wait error:"); | ||
exit(1); | ||
} | ||
|
||
while(i < 3) { | ||
printf("Parent Pid = %d, SonPid = %d\n", getpid(), pid); | ||
sleep(1); | ||
i++; | ||
} | ||
|
||
printf("Parent: Status %d WIFEXITED(status) == %d\n", status, WIFEXITED(status)); | ||
|
||
//WEXITSTATUS get the return code | ||
printf("Parent: Status %d The return code WEXITSTATUS(status) == %d\n", status, WEXITSTATUS(status)); | ||
} else { | ||
perror("for error"); | ||
exit(1); | ||
} | ||
|
||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <signal.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
// // #define WEXITSTATUS(s) (((s)&0xff00) >> 8) | ||
// // #define WIFEXITED(s) (!WTERMSIG(s)) | ||
// #define WIFEXITED(s) ((s)&0x7f) | ||
|
||
int main(void) | ||
{ | ||
pid_t pid, wpid; | ||
int status; | ||
int i = 0; | ||
pid = fork(); | ||
// printf(" %d \n", pid); | ||
if (pid == -1) { | ||
// fork失败 | ||
perror("fork failed"); | ||
exit(EXIT_FAILURE); | ||
} else if (pid == 0) { //子进程 | ||
printf("Child --- My Parent is %d\n", getppid()); | ||
sleep(5); | ||
// 子进程的任务完成,现在退出 | ||
printf("Child Process is exiting\n"); | ||
exit(0); // 退出子进程 | ||
} else if(pid > 0) { //父进程 | ||
wpid = wait(&status); //等待回收子进程 | ||
|
||
printf("Status %d\n", status); | ||
|
||
if(wpid == -1) { | ||
perror("wait error:"); | ||
exit(1); | ||
} | ||
|
||
while(i < 3) { | ||
printf("Parent Pid = %d, SonPid = %d\n", getpid(), pid); | ||
sleep(1); | ||
i++; | ||
} | ||
|
||
printf("Parent: Status %d WIFEXITED(status) == %d\n", status, WIFEXITED(status)); | ||
|
||
//WEXITSTATUS get the return code | ||
printf("Parent: Status %d The return code WEXITSTATUS(status) == %d\n", status, WEXITSTATUS(status)); | ||
} else { | ||
perror("for error"); | ||
exit(1); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters