fork() returns a process ID AKA PID, there are three instances;
- if PID < 0, fork() returns a negative value, the creation of a child process was unsuccessful.
- if PID ==0, fork() returns a zero to the newly created child process.
- if PID > 0, fork() returns a positive value, the process ID of the child process, to the parent.
- Variables initialized before the fork() call have the same values in both address spaces.
- Modifications done in each process will be independent.
#include <signal.h>
#include <stdio.h>
void main()
{
int pid;
printf("Parent process ID %d \n",getpid());
pid = fork();
if (pid==0) {
printf("Child process ID %d \n",getpid());
int x;
printf("Enter Value : ");
scanf("%d",&x);
printf("Entered Value : %d",x);
} else if (pid > 0) {
sleep(5);// parent stops execution for 5 seconds
printf("Parent process ID %d \n",getpid());
}
}


A good and very valuble post......got a something in ur post.....thanx(if u can remove the word verification then will be easy to do comment)
ReplyDeleteThanks a lot...
ReplyDeletenice post
ReplyDelete