CSL206 Operating Systems Lab

1. Write a program to create a process in linux.

ALGORITHM

 

 1. Start program.

2.· Assign fork() system call to pid.

3. if pid is equal to -1, child process not created.

4.if pid is equal to 0, child process will be created.

5.Print the id of parent process and child process.

6.Create another one child process in same loop.

7. Print id of parent process and the child process.

8.Print grand parent id.

9. Stop the program.

PROGRAM

#include<sys/types.h>

#include<stdio.h>

#include<process.h>

int main()

{

int pid_t,pid,pid1,p,p1;

pid =fork();

if (pid ==-1)

{

printf("enter in connection");

}

else

if(pid==0)

{

printf("\n child process1 :\n\n");

p=getppid();

printf("parent process id of child1: %d\n",p);

p1=getpid();

printf("parent process id of child1: %d\n",p1);

}

else

{

pid1=fork();

if(pid==0)

{

printf("\nchild process 2:\n\n");

p=getppid();

printf("parent process id of child2: %d\n",p);

p1=grtpid();

printf("parent process id of child2: %d\n",p1);

}


else

{

printf("this is parent process \n");

p=getppid();

printf("grant parent: %d \n",p);

p1=getpid();

printf("process id of parent: %d \n",p1);

}

}

return

}


Comments

Popular posts from this blog

Pentium microprocessors

Multilevel Organization of Cache Memory