0% found this document useful (0 votes)
2 views7 pages

Process Updated

The document describes the creation of processes in C programming, including examples of child process creation, orphan process creation, and zombie process creation. Each section includes code snippets demonstrating the behavior of parent and child processes, along with expected outputs. The document highlights the use of the fork() system call and the implications of process termination and parent-child relationships.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

Process Updated

The document describes the creation of processes in C programming, including examples of child process creation, orphan process creation, and zombie process creation. Each section includes code snippets demonstrating the behavior of parent and child processes, along with expected outputs. The document highlights the use of the fork() system call and the implications of process termination and parent-child relationships.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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:

You might also like