You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
644 B
29 lines
644 B
2 years ago
|
/*
|
||
2 years ago
|
* The application of lab3_3.
|
||
|
* parent and child processes never give up their processor during execution.
|
||
2 years ago
|
*/
|
||
|
|
||
|
#include "user/user_lib.h"
|
||
|
#include "util/types.h"
|
||
|
|
||
|
int main(void) {
|
||
|
uint64 pid = fork();
|
||
2 years ago
|
uint64 rounds = 100000000;
|
||
|
uint64 interval = 10000000;
|
||
|
uint64 a = 0;
|
||
2 years ago
|
if (pid == 0) {
|
||
|
printu("Child: Hello world! \n");
|
||
|
for (uint64 i = 0; i < rounds; ++i) {
|
||
2 years ago
|
if (i % interval == 0) printu("Child running %ld \n", i);
|
||
2 years ago
|
}
|
||
|
} else {
|
||
|
printu("Parent: Hello world! \n");
|
||
|
for (uint64 i = 0; i < rounds; ++i) {
|
||
2 years ago
|
if (i % interval == 0) printu("Parent running %ld \n", i);
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
|
exit(0);
|
||
|
return 0;
|
||
|
}
|