Question: 1. Type the following C program, that will fork() a separate process: #include int main(void) { int i; /* Process Creation */ i = fork();
1.Type the following C program, that will fork() a separate process:
#include
int main(void)
{
int i;
/* Process Creation */
i = fork();
printf("Hello World ");
exit(0);
}
Call the above program p1.c, and compile it as follows: gcc -o p1 p1.c
Then Execute p1.
Questions:
1.1 How many times do you see the Hello World message in the output?
1.2 Explain why?
2. fork() system call returns twice, one for each process that is running. At the time the fork() is called, the original process is cloned and begins executing simultaneously. The only distinction between the two processes is the return value from the fork() call.
PARENT has the return value >0 indicating the child's process ID.
CHILD has a return value =0
A return value <0 indicates an error on fork(), which could happen if there was no memory or process table space in the system.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
