Forkexpe

228 views
200 views

Published on

Hackintoshrao:codes for GNU/LINUX
ILLUSTRATION OF ORPHAN PROCESS AND ASSIGNMENT OF INIT AS A PARENT TO SUCH A PROCESS
SYSTEM CALLS USED
1.fork()
2.getpid()
3.getppid()
4.sleep()
*/
#include<stdlib>
#include<unistd>
#include<time>
int main()
{
int pid;
pid=fork();
if(pid==0)
{


printf("\nChild process here \n");
printf("\nchild here..Parent id=%d,Process id=%d\n",getppid(),getpid());
sleep(3);
printf("\nChild process here,now its a orphan process,so init is my parent process now \n");
printf("\nchild here...Parent id=%d,Process id=%d\n",getppid(),getpid());
/*its clearly evident in the o/p that the parent process Id of the child process will now be =1,
the init process is made as a parent */
}
else{
sleep(1);
/*since parent process finishes earlier than the child ,the latter becomes a orphan process */
printf("\nparent process here \n");
printf("\nparent process..Process id=%d\n",getpid());
printf("\nparent process Exiting,making the child process a orphan .......\n\n") ;

}
}

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
228
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Forkexpe

  1. 1. /* Hackintoshrao:codes for GNU/LINUX ILLUSTRATION OF ORPHAN PROCESS AND ASSIGNMENT OF INIT AS A PARENT TO SUCH APROCESS SYSTEM CALLS USED 1.fork() 2.getpid() 3.getppid() 4.sleep() */#include<stdlib.h>#include<unistd.h>#include<time.h>int main(){ int pid; pid=fork(); if(pid==0) { printf("nChild process here n"); printf("nchild here..Parent id=%d,Process id=%dn",getppid(),getpid()); sleep(3); printf("nChild process here,now its a orphan process,so init is my parentprocess now n"); printf("nchild here...Parent id=%d,Process id=%dn",getppid(),getpid()); /*its clearly evident in the o/p that the parent process Id of the childprocess will now be =1, the init process is made as a parent */ } else{ sleep(1); /*since parent process finishes earlier than the child ,the latter becomesa orphan process */ printf("nparent process here n"); printf("nparent process..Process id=%dn",getpid()); printf("nparent process Exiting,making the child process a orphan .......nn") ; }}

×