feat: update structure

This commit is contained in:
2024-01-22 14:27:40 +08:00
parent 7836c9185c
commit 3544a28a2e
559 changed files with 120846 additions and 4102 deletions

View File

@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int slow(char *name, int time, int n) {
for(int i=n; i<=n+4; i++) {
printf("%s: i = %d\n", name, i);
sleep(time);
}
}
sdf
asdf
as
dfas
f
int main() {
int id;
if((id = fork()) != 0) {
int stat;
int my_id = getpid();
int parent_id = getppid();
printf("\nI am the parent.\n");
printf("My ID is %d\n", my_id);
printf("My parent's ID is %d\n", parent_id);
printf("My child's ID is %d\n\n", id);
slow("Parent", 1, 5);
printf("\nWaiting for child to exit.\n");
wait(&stat);
printf("CHILD HAS EXITED WITH STATUS %d\n", WEXITSTATUS(stat));
}
else
{
id = getpid();
int parent_id = getppid();
printf("\nI am the child.\n");
printf("My ID is %d\n", id);
printf("My parent's ID is %d\n\n", parent_id);
slow("Child", 2, 10);
exit(25);
}
}