My name is Fatima Execute the code using Linux interfaces Make the file name your own, for example (touch seaid.c) Take a picture of the input and output Program 4:1 Orphan process //orphan process #include #include int main ( ) { int pid ; printf ("I'am the original process with PID %d and PPID %d.\n", getpid ( ), getppid ( ) ) ; pid = fork ( ) ; /* Duplicate. Child and parent continue from here */ if ( pid != 0 ) /* pid is non-zero, so I must be the parent */ { printf ("I'am the parent process with PID %d and PPID %d.\n", getpid ( ), getppid ( ) ) ; printf ("My child's PID is %d\n", pid ) ; } else /* pid is zero, so I must be the child */ { sleep (4) ; /* make sure that the parent terminates first */ printf ("I'am the child process with PID %d and PPID %d.\n", getpid ( ), getppid ( ) ) ; } printf ("PID %d terminates.\n", getpid ( ) ) ;
My name is Fatima
Execute the code using Linux interfaces
Make the file name your own, for example (touch seaid.c)
Take a picture of the input and output
Program 4:1 Orphan process
//orphan process
#include <stdio.h>
#include<unistd.h>
int main ( )
{
int pid ;
printf ("I'am the original process with PID %d and PPID %d.\n", getpid (
), getppid ( ) ) ;
pid = fork ( ) ; /* Duplicate. Child and parent continue from here */
if ( pid != 0 ) /* pid is non-zero, so I must be the parent */
{
printf ("I'am the parent process with PID %d and PPID %d.\n", getpid (
), getppid ( ) ) ;
printf ("My child's PID is %d\n", pid ) ;
}
else /* pid is zero, so I must be the child */
{
sleep (4) ; /* make sure that the parent terminates first */
printf ("I'am the child process with PID %d and PPID %d.\n", getpid ( ),
getppid ( ) ) ;
}
printf ("PID %d terminates.\n", getpid ( ) ) ;
}
Step by step
Solved in 3 steps with 2 images