parent
448d994bba
commit
452a824e9d
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This app fork a child process to read and write the heap data from parent process.
|
||||
* Because implemented copy on write, when child process only read the heap data,
|
||||
* the physical address is the same as the parent process.
|
||||
* But after writing, child process heap will have different physical address.
|
||||
*/
|
||||
|
||||
#include "user/user_lib.h"
|
||||
#include "util/types.h"
|
||||
|
||||
int main(void) {
|
||||
int *heap_data = naive_malloc();
|
||||
printu("the physical address of parent process heap is: ");
|
||||
printpa(heap_data);
|
||||
int pid = fork();
|
||||
if (pid == 0) {
|
||||
printu("the physical address of child process heap before copy on write is: ");
|
||||
printpa(heap_data);
|
||||
heap_data[0] = 0;
|
||||
printu("the physical address of child process heap after copy on write is: ");
|
||||
printpa(heap_data);
|
||||
}
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
@ -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;
|
||||
}
|
Loading…
Reference in new issue