Add documentation to program to explain its functionality Ad
Add documentation to program to explain its functionality
Add a header comment to the top of the program explaining the overall purpose of the program.
Add internal comments within the program to explain the purpose of different sections of the program.
Create a short of description of WHY the program works the way it does. Do not just document the output of the program… you must also explain why the program provides that output.
Program:
fork1.c
/* fork1.c - Demonstrate the fork() */
#include <stdio.h>
#include <unistd.h>
main()
{
int i;
printf(\"Ready to fork...\ \");
i=fork();
printf(\"Fork returned %d\ \",i);
}
Solution
main()
{
int i; //declares a variable i which is an integer
printf(\"Ready to fork...\ \"); //prints ready to fork.
i=fork(); // creates a process which becomes child process
printf(\"Fork returned %d\ \",i); prints fork returned with the process ID.
}
fork() is a system call and this is used to create a new process. It takes no arguments and it returns the process ID. The main aim of ofrk is ot create a new process which is known as the child process.
fork() returns a negative value if the creation of a child process was unsuccessful.
fork() returns a zero to the newly created child process.
fork() returns a positive value if the process ID of the child process, to the parent.
