#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid;
// Step 1: Fork a new process
pid = fork();
// Step 2: Check if fork was successful
if (pid < 0) {
// Fork failed
fprintf(stderr, "Fork failed\n");
return 1;
} else if (pid == 0) {
// Step 3: Code for child process
printf("This is the child process, PID = %d\n", getpid());
} else {
// Step 4: Code for parent process
printf("This is the parent process, PID = %d\n", getpid());
printf("Child PID = %d\n", pid);
}
// Step 5: Common code for both parent and child processes
printf("This is common code for both processes\n");
return 0;
}