parent
							
								
									1f568dd6e1
								
							
						
					
					
						commit
						d75447ab6d
					
				| @ -1,18 +0,0 @@ | ||||
| /*
 | ||||
|  * The application of lab3_1. | ||||
|  * it simply forks a child process. | ||||
|  */ | ||||
| 
 | ||||
| #include "user/user_lib.h" | ||||
| #include "util/types.h" | ||||
| 
 | ||||
| int main(void) { | ||||
|   uint64 pid = fork(); | ||||
|   if (pid == 0) { | ||||
|     printu("Child: Hello world!\n"); | ||||
|   } else { | ||||
|     printu("Parent: Hello world! child id %ld\n", pid); | ||||
|   } | ||||
| 
 | ||||
|   exit(0); | ||||
| } | ||||
| @ -0,0 +1,32 @@ | ||||
| /*
 | ||||
|  * The application of lab3_2. | ||||
|  * parent and child processes intermittently give up their processors. | ||||
|  */ | ||||
| 
 | ||||
| #include "user/user_lib.h" | ||||
| #include "util/types.h" | ||||
| 
 | ||||
| int main(void) { | ||||
|   uint64 pid = fork(); | ||||
|   uint64 rounds = 0xffff; | ||||
|   if (pid == 0) { | ||||
|     printu("Child: Hello world! \n"); | ||||
|     for (uint64 i = 0; i < rounds; ++i) { | ||||
|       if (i % 10000 == 0) { | ||||
|         printu("Child running %ld \n", i); | ||||
|         yield(); | ||||
|       } | ||||
|     } | ||||
|   } else { | ||||
|     printu("Parent: Hello world! \n"); | ||||
|     for (uint64 i = 0; i < rounds; ++i) { | ||||
|       if (i % 10000 == 0) { | ||||
|         printu("Parent running %ld \n", i); | ||||
|         yield(); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   exit(0); | ||||
|   return 0; | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue