添加以前的作业

This commit is contained in:
2026-05-15 21:25:01 +08:00
parent fa2f3e2413
commit 56a4233098
10 changed files with 1558 additions and 0 deletions

54
exp0.5/task51.c Normal file
View File

@@ -0,0 +1,54 @@
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(){
__pid_t pid;
//父进程输出
printf("P1:I am father process,PID=%d,PPID=%d\n", getpid(), getppid());
//生成子进程
pid = fork();
//父进程
if(pid != 0){
//pid判断归零
pid = 0;
pid = fork();
//子进程
if (pid == 0){
printf("P12:I am young brother process,PID=%d,PPID=%d\n", getpid(), getppid());
//此时pid为0继续生成子进程
pid = fork();
if (pid == 0){
printf("P121:我的学号是2024414290124,PID=%d,PPID=%d\n", getpid(), getppid());
}
//父进程
else{
//pid判断归零
pid = 0;
pid = fork();
//子进程
if (pid == 0){
printf("P122:我的姓名是吕锦中,PID=%d,PPID=%d\n", getpid(), getppid());
}
//父进程
else{
}
}
}
//父进程
else{
}
}
//子进程
else{
time_t t = time(NULL);
printf("P11:当前时间是:%s,PID=%d,PPID=%d\n", ctime(&t), getpid(), getppid());
}
}