Files
OS_Emil_Shanayev/Lab4/ex1.c
T
2024-09-24 17:51:28 +03:00

52 lines
779 B
C

#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main(void) {
/*
int n = 4;
for (int i = 0; i < 10 ; i++) {
pid_t pid1 = fork();
printf("PID:%d n:%d &n:%d\n", pid1, n, &n);
}
*/
pid_t pid = fork();
if (pid == 0) {
printf("PID1: %d\n", getpid());
}
else {
sleep(3);
printf("PPID: %d\n", getpid());
}
if (pid != 0) {
sleep(3);
kill(pid, SIGKILL);
wait(NULL);
}
pid_t pid_2 = fork();
if (pid_2 == 0) {
printf("PID2: %d\n", getpid());
}
else {
printf("PPID: %d\n", getpid());
}
if (pid == 0) {
sleep(3);
kill(getppid(), SIGKILL);
}
return 0;
}