Process Creation:
Name: Ashutosh Gupta
Registration Number: 24BCE2983
First Code Child Creation:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
pid_t pid = fork();
printf("Fork returned: %d\n", pid);
if (pid == 0) {
printf("Inside Child process");
printf("Child PID: %d\n", getpid());
printf("Child's Parent PID: %d\n", getppid());
else {
printf("Inside Parent process");
printf("Parent PID: %d, Child PID: %d\n", getpid(), pid);
printf("Parent's Child PID: %d\n", pid);
if (pid < 0) {
printf("Fork failed\n");
return 0;
}
SS of Code:
Output SS:
Second Code: Orphan creation
Code:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
pid_t pid = fork();
if (pid < 0) {
printf("Fork failed\n");
return 1;
if (pid == 0) {
/* Child process execution */
printf("Inside Child process\n");
printf("Child PID: %d, Initial Parent PID: %d\n", getpid(), getppid());
/* Sleep allows parent process to exit first */
sleep(5);
printf("\nAfter parent exited:\n");
printf("Inside Child process (Orphaned)\n");
printf("Child PID: %d, Adopted Parent PID: %d\n", getpid(), getppid());
else {
/* Parent process execution */
printf("Inside Parent process\n");
printf("Parent PID: %d, Exiting immediately...\n", getpid());
/* Parent exits without waiting for child */
return 0;
Code SS:
Output SS:
Third Code: Zombie Process Creation
Code :
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
pid_t pid = fork();
if (pid < 0) {
printf("Fork failed\n");
return 1;
if (pid == 0) {
/* Child process execution */
printf("Inside Child process\n");
printf("Child PID: %d, Exiting immediately...\n", getpid());
/* Child terminates immediately */
else {
/* Parent process execution */
printf("Inside Parent process\n");
printf("Parent PID: %d, Child PID: %d\n", getpid(), pid);
printf("Parent sleeping for 15 seconds without calling wait()...\n");
/* Parent stays alive while child has terminated */
sleep(15);
printf("Parent woke up and exiting now.\n");
return 0;
Code SS:
Output SS: