Write a C program that illustrates how an orphan is created.
AIM:
Write a C program that illustrates how an orphan is created.
Program:
#include <stdio.h> main() { int pid ; printf("I'am the original process with PID %d and PPID %d.\n",getpid(),getppid()); pid=fork(); if(pid!=0 ) { printf("I'am the parent with PID %d and PPID %d.\n",getpid(),getppid()); printf("My child's PID is %d\n",pid) ; } else { sleep(4); printf("I'm the child with PID %d and PPID %d.\n",getpid(), getppid()) ; } printf ("PID %d terminates.\n", getpid()) ; }
Output:
guest-glcbIs@ubuntu:~$gcc –o prg18.out prg18.c guest-glcbIs@ubuntu:~$./prg18.out I am the original process with PID2242 and PPID1677. I am the parent with PID2242 and PPID1677 My child’s PID is 2243 PID2243 terminates. $ I am the child with PID2243 and PPID1. PID2243 termanates.
-
UpdatedOct 23, 2014
-
Views9,827
You May Like
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.