Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
os lab2-4

os lab2-4

Ratings: (0)|Views: 16|Likes:
Published by Mohana Krishna

More info:

Published by: Mohana Krishna on Jan 16, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

09/27/2013

pdf

text

original

 
EX.NO:2
TO ILLUSTRATE THE USE OF fork () ANDgetpid () SYSTEM CALLS
FORK & GETPIDAim :
To Create a process in the following hierarchyParentChild1Child2Child3
Algorithm
1.
 
Declare the necessary variables.2.
 
Parent process is the process of the program which is running.3.
 
Create the child1 process using fork() When parent is active.4.
 
Create the child2 process using fork() when child1 is active.5.
 
Create the child3 process using fork() when child2 is active.
FORK ( ) & GETPID ( )
#include<stdio.h>void main(){int pid1,pid2,pid3;printf("Parent id is %d and root id is %d\n",getpid(),getppid());
 
pid1=fork();if(pid1==0){printf("Process 1 id is %d and its parent id is %d\n",getpid(),getppid());pid2=fork();}if(pid2==0){printf("Process 2 id is %d and its parent id is %d\n",getpid(),getppid());pid3=fork();}if(pid1==0&&pid2==0&&pid3==0){printf("Process 3 id is %d and its parent id is %d\n",getpid(),getppid());}}
ESULT:
Thus the process id, value were printed by using the fork and getpid system calls.
TO DEMONSTRATE EXECLP ( ) FUNCTION
AIM:
 To write a shell program to implement the execlp( ) function .
ALGORITHM:
 
1. Start the program.2. Obtain the pid value using fork ( ) function.3. If pid < 0, then print fork failed.4. Else if pid = 0 , execlp( ) function will invoked .5. Else print child process complete.6. Terminate the program.
//#include<unistd.h>//#include<stdio.h>//#include<sys/types.h>#include <stdio.h> /* printf, stderr, fprintf */#include <unistd.h> /* _exit, fork */#include <stdlib.h> /* exit */#include <errno.h> /* errno */main(int argc,char *argv[]){int pid;pid =fork();if(pid<0){printf(stderr,"Fork failed \n");

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->