Initial commit
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
#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;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user