You are on page 1of 4

VIGNAN UNIVERSITY

Class: M.TECH EXP NO: ROLL NO:131FB06008

VFORK DEMO

AIM: To write a program for FORK DEMO in real time operating system.

APPARATUS:
-PC
- LINUX Terminal.

ALGORITHM FOR VFORK DEMO:

1.start

2.initialise variables

3.the processid returned by vfork() is stored in pid

4.check pid

5. if pid is zero child process is created, otherwise parent process is created

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:

HENCE THE PROGRAM IS EXECUTED SUCCESSFULLY AND OUTPUT


VERIFIED.

You might also like