SlideShare a Scribd company logo
1 of 27
Group E4
20CP205 AVNI ROHIT
21CP308 PARAM PATEL
21CP310 IRBAAZ VOHRA
1. Demonstrate the use of fork system call.
• Fork system call is used to create a new process, called the child
process.
• Child process runs concurrently with the process that makes the
fork() call, i.e. parent process.
• After a new child process is created, both processes will execute the
next instruction followed by the fork() system call.
• The fork() takes no parameters and returns an integer value.
• If the value < 0, then the creation of the child process failed.
• If value = 0, then returned to the newly created child process
• If value > 0, then parent is returned, and value = PID of child
process.
What is the output of the
following program?
 A)
 int main()
 {
 fork();
 printf("nHellon");
 return 0;
 }
OUTPUT
Parent
Process
Child
Process
Parent
Process
 B)
 int main()
 {
 fork();
 fork();
 printf("nHellon");
 return 0;
 }
Parent
Process
Parent
Process
Child
Process
(C1)
Parent
Process
Child
Process
(C2)
Child
Process
(C1)
Child
Process
(C3)
OUTPUT
2. Demonstrate printing PID of child
and parent process.
 #include <stdio.h>
 #include <sys/types.h>
 #include <unistd.h>
 int main()
 {
 int id = fork();
 if(id==0)
 {
 printf("nChild Process PID : %dn",getpid()
 printf("nParent PID : %dn",getppid());
 }
 else
 {
 printf(“nParent Process PID : %dn",getpid());
 sleep(2);
 }
 return 0;
 }
3. Demonstrate use of wait system call. How parent knows child
terminate normally or abnormally after checking return values of
wait .
A)
OUTPUT
B)
OUTPUT
4.Demonstrate use of execl, execv, execve, execlp,
execvp, execle.
 Execl :
execl() call replaces the image of the current process with
a new process image specified by the path i.e. the current
process code gets replaced by a new process code.
 Execv(path,argv) :
causes the current process to abandon the program that it is
running and start running the program in file path. Parameter
argv is the argument vector for the command, with a null
pointer at the end. It is an array of strings.
 Execve :
execve() executes the program pointed to by filename.
filename must be either a binary executable,
 execlp :
The execlp function is most commonly used to overlay a
process image that has been created by a call to the fork
function. identifies the location of the new process image
within the hierarchical file system (HFS).
 execvp and execle :
These two also serve the same purpose but the syntax of them
are a bit different from all the above members of exec family.
The syntaxes of both of them are shown below :
Syntax: int execvpe(const char *file, char *const argv[],char
*const envp[]);
Syntax:int execle(const char path, const char *arg, .../, (char
*) NULL, char * const envp[] */);
 5. Demonstrate Zombie Process and Orphan Process
 Zombie Process: A Process Which Terminate But Whose
Parent Not Yet Called Wait() is Known As Zombie Process
 Once The Parent Calls Wait() the Process Identifier of the
Process and its entry in the Zombie process the table is
released
 A child Process Always First Becomes a Zombie Before
Removed From the Process Table
 #include<stdio.h>
 #include<unistd.h>
 int main()
 {
 pid_t t;
 t=fork();
 if(t==0)
 {
 printf("Child having id %dn",getpid());
 }
 else
 {
 printf("Parent having id %dn",getpid());
 sleep(15); // Parent sleeps. Run the ps command
 }
 }
 Output :
 $gcc zombie.c
 $./a.out &
Orphan Process :
 A Process Whose Parent Process no More Exist i.e. either finished or
Terminated Without Waiting for Its Child Process To Terminate Is
Called an Orphan Process
 The Init Process Is Assigned As The New Parent To Orphan Process
 The Init Process Periodically Invokes wait(), There By Allowing The
Exit Status Of Any Orphaned Process to be collected and Relesing
Orphans Process identifier and Process Entry Table
#include<stdio.h >
 #include<unistd.h>
 #include<sys/types.h>
 int main()
 {
 pid_t p;
 p=fork();
 if(p==0)
 {
 sleep(5); //child goes to sleep and in the mean time parent
 terminates
 printf("I am child having PID %dn",getpid());
 printf("My parent PID is %dn",getppid());
 }
 else
 {
 Output :
6. Develop user defined function which allow to run
binary file and give control back to your parent process
similar to library function system
 Ex1.c
 #include<stdio.h>
 #include<unistd.h>
 #include<stdlib.h>
 Int main(int argc,char *argv[])
 {
 Printf(“PID of EX1.c= %dn”, getpid());
 Char *args[] = {“Hello”,”Vahora”,”Irbaz”,NULL};
 Execv(“./ex2”,args);
 Printf(“Back To ex1.c”);
 Return 0;
}
 Ex2.c
 #include<stdio.h>
 #include<unistd.h>
 #include<stdlib.h>
 Int main(int argc,char *argv[])
 {
 Printf(“We Are In Ex2.cn”)
 Printf(“PID of EX2.c= %dn”, getpid());
 Return 0;
}
OUTPUT
OS presentation (1).pptx

More Related Content

Similar to OS presentation (1).pptx

04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptxvnwzympx
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.pptSIDDHARTHANANDCSE202
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxstilliegeorgiana
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxdenneymargareta
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummaryAmal Khailtash
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxadampcarr67227
 
Program Assignment Process ManagementObjective This program a.docx
Program Assignment  Process ManagementObjective This program a.docxProgram Assignment  Process ManagementObjective This program a.docx
Program Assignment Process ManagementObjective This program a.docxwkyra78
 
System Calls - Introduction
System Calls - IntroductionSystem Calls - Introduction
System Calls - IntroductionTo Sum It Up
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Samuel Lampa
 
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونیMohammad Reza Kamalifard
 
Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File UploadJoe Suh
 
Lecture2 process structure and programming
Lecture2   process structure and programmingLecture2   process structure and programming
Lecture2 process structure and programmingMohammed Farrag
 
UNIX_Process Control_Module3.pptx
UNIX_Process Control_Module3.pptxUNIX_Process Control_Module3.pptx
UNIX_Process Control_Module3.pptxraunakkumar290158
 
エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理maruyama097
 

Similar to OS presentation (1).pptx (20)

04_ForkPipe.pptx
04_ForkPipe.pptx04_ForkPipe.pptx
04_ForkPipe.pptx
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
 
Programming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docxProgramming Assignment #2CSci 430 Spring 2019Dates.docx
Programming Assignment #2CSci 430 Spring 2019Dates.docx
 
SystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features SummarySystemVerilog OOP Ovm Features Summary
SystemVerilog OOP Ovm Features Summary
 
httplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docxhttplinux.die.netman3execfork() creates a new process by.docx
httplinux.die.netman3execfork() creates a new process by.docx
 
Lect3 process
Lect3 processLect3 process
Lect3 process
 
Program Assignment Process ManagementObjective This program a.docx
Program Assignment  Process ManagementObjective This program a.docxProgram Assignment  Process ManagementObjective This program a.docx
Program Assignment Process ManagementObjective This program a.docx
 
Proces
ProcesProces
Proces
 
System Calls - Introduction
System Calls - IntroductionSystem Calls - Introduction
System Calls - Introduction
 
Java programs
Java programsJava programs
Java programs
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...
 
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونیاسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
 
Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File Upload
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
Lecture2 process structure and programming
Lecture2   process structure and programmingLecture2   process structure and programming
Lecture2 process structure and programming
 
UNIX_Process Control_Module3.pptx
UNIX_Process Control_Module3.pptxUNIX_Process Control_Module3.pptx
UNIX_Process Control_Module3.pptx
 
エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理エンタープライズ・クラウドと 並列・分散・非同期処理
エンタープライズ・クラウドと 並列・分散・非同期処理
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 

Recently uploaded

Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 

OS presentation (1).pptx

  • 1. Group E4 20CP205 AVNI ROHIT 21CP308 PARAM PATEL 21CP310 IRBAAZ VOHRA
  • 2. 1. Demonstrate the use of fork system call. • Fork system call is used to create a new process, called the child process. • Child process runs concurrently with the process that makes the fork() call, i.e. parent process. • After a new child process is created, both processes will execute the next instruction followed by the fork() system call. • The fork() takes no parameters and returns an integer value. • If the value < 0, then the creation of the child process failed. • If value = 0, then returned to the newly created child process • If value > 0, then parent is returned, and value = PID of child process.
  • 3. What is the output of the following program?  A)  int main()  {  fork();  printf("nHellon");  return 0;  }
  • 5.  B)  int main()  {  fork();  fork();  printf("nHellon");  return 0;  } Parent Process Parent Process Child Process (C1) Parent Process Child Process (C2) Child Process (C1) Child Process (C3)
  • 7. 2. Demonstrate printing PID of child and parent process.  #include <stdio.h>  #include <sys/types.h>  #include <unistd.h>  int main()  {  int id = fork();  if(id==0)  {  printf("nChild Process PID : %dn",getpid()  printf("nParent PID : %dn",getppid());  }
  • 8.  else  {  printf(“nParent Process PID : %dn",getpid());  sleep(2);  }  return 0;  }
  • 9.
  • 10. 3. Demonstrate use of wait system call. How parent knows child terminate normally or abnormally after checking return values of wait . A)
  • 12. B)
  • 14. 4.Demonstrate use of execl, execv, execve, execlp, execvp, execle.  Execl : execl() call replaces the image of the current process with a new process image specified by the path i.e. the current process code gets replaced by a new process code.
  • 15.  Execv(path,argv) : causes the current process to abandon the program that it is running and start running the program in file path. Parameter argv is the argument vector for the command, with a null pointer at the end. It is an array of strings.  Execve : execve() executes the program pointed to by filename. filename must be either a binary executable,
  • 16.  execlp : The execlp function is most commonly used to overlay a process image that has been created by a call to the fork function. identifies the location of the new process image within the hierarchical file system (HFS).
  • 17.  execvp and execle : These two also serve the same purpose but the syntax of them are a bit different from all the above members of exec family. The syntaxes of both of them are shown below : Syntax: int execvpe(const char *file, char *const argv[],char *const envp[]); Syntax:int execle(const char path, const char *arg, .../, (char *) NULL, char * const envp[] */);
  • 18.  5. Demonstrate Zombie Process and Orphan Process  Zombie Process: A Process Which Terminate But Whose Parent Not Yet Called Wait() is Known As Zombie Process  Once The Parent Calls Wait() the Process Identifier of the Process and its entry in the Zombie process the table is released  A child Process Always First Becomes a Zombie Before Removed From the Process Table
  • 19.  #include<stdio.h>  #include<unistd.h>  int main()  {  pid_t t;  t=fork();  if(t==0)  {  printf("Child having id %dn",getpid());  }  else  {  printf("Parent having id %dn",getpid());  sleep(15); // Parent sleeps. Run the ps command  }  }
  • 20.  Output :  $gcc zombie.c  $./a.out &
  • 21. Orphan Process :  A Process Whose Parent Process no More Exist i.e. either finished or Terminated Without Waiting for Its Child Process To Terminate Is Called an Orphan Process  The Init Process Is Assigned As The New Parent To Orphan Process  The Init Process Periodically Invokes wait(), There By Allowing The Exit Status Of Any Orphaned Process to be collected and Relesing Orphans Process identifier and Process Entry Table
  • 22. #include<stdio.h >  #include<unistd.h>  #include<sys/types.h>  int main()  {  pid_t p;  p=fork();  if(p==0)  {  sleep(5); //child goes to sleep and in the mean time parent  terminates  printf("I am child having PID %dn",getpid());  printf("My parent PID is %dn",getppid());  }  else  {
  • 24. 6. Develop user defined function which allow to run binary file and give control back to your parent process similar to library function system  Ex1.c  #include<stdio.h>  #include<unistd.h>  #include<stdlib.h>  Int main(int argc,char *argv[])  {  Printf(“PID of EX1.c= %dn”, getpid());  Char *args[] = {“Hello”,”Vahora”,”Irbaz”,NULL};  Execv(“./ex2”,args);  Printf(“Back To ex1.c”);  Return 0; }
  • 25.  Ex2.c  #include<stdio.h>  #include<unistd.h>  #include<stdlib.h>  Int main(int argc,char *argv[])  {  Printf(“We Are In Ex2.cn”)  Printf(“PID of EX2.c= %dn”, getpid());  Return 0; }