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:
fork3.c
/* fork3.c - fork can be called iteratively */
#include <stdio.h>
#include <unistd.h>
main()
{
int i;
i=getpid();
printf(\"Parent=%d\ \",i);
fork();
fork();
i=getpid();
printf(\"Who am I? %d\ \",i);
}
Solution
#include <stdio.h>
#include <unistd.h> // It is used when e use standard symbolic constants and types in our program
void main()
{
int i;
i=getpid(); // This function retrieve the process id
printf(\"Parent=%d\ \",i);
/* fork( ) function is used to create new processes and these new processes acts as child process
Each fork() function will execute both parent and child process
That`s why while we compile we are getting last statement repeating 4 times as we wrote 2 fork() functions
*/
fork();
fork();
// Here getpid() function return process id
i=getpid();
printf(\"Who am I? %d\ \",i);
}
If you have any further doubts regarding this please feel free to ask, thankyou

