B3: C/C++ Program to Parent creating the child process by use of fork.
Program:
#include<stdio.h>
#include<unistd.h>
int main()
{
intpid;
pid=fork();
if(pid==0)
{
printf("\n
After fork");
printf("\n
The new child process created by fork system call %d\n", getpid());
printf("\n
The parent process id is :- %d ", getppid());
}
else {
printf("\n
Befor fork");
printf("\n
The parent process id is :- %d ", getpid());
printf("\n
parent excuted successfully\n");
}
return
0;
}
Output:
[student@localhost
~]$ gccfork.c
[student@localhost
~]$ ./a.out
Befor fork
The parent process id is :- 1792
parentexcuted
successfully
After fork
The new child process created by fork system
call 1793
The parent process id is :- 1792
[student@localhost ~]$
0 comments:
Post a Comment