Professional Documents
Culture Documents
VFORK DEMO
AIM: To write a program for FORK DEMO in real time operating system.
APPARATUS:
-PC
- LINUX Terminal.
1.start
2.initialise variables
4.check pid
6. end
DESCRIPTION:
FORK FUNCTION:
Name: Fork - create a new process
Synopsis: #include <unistd.h>
pid_t fork(void);
on successful completion, fork() shall return 0 to the child process and shall return the
process ID of the child process to the parent process.
Both processes shall continue to execute from the fork() function. Otherwise, -1 shall be
returned to the parent process, no child process shall be created,
and errno shall be set to indicate the error.
PROGRAM:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
void main()
1
VIGNAN UNIVERSITY
Class: M.TECH EXP NO: ROLL NO:131FB06008
{
int i;
pid_t pid;
pid=vfork();
i=(int) pid;
while(1)
{
if(pid== 0)
printf("i m child %d \n",i);
else
printf("i m parent %d\n",i);
}
}
2
VIGNAN UNIVERSITY
Class: M.TECH EXP NO: ROLL NO:131FB06008
OUT PUT:
3
VIGNAN UNIVERSITY
Class: M.TECH EXP NO: ROLL NO:131FB06008
RESULT: