/*here is the program */
#include<stdio.h>
#include<sched.h>
#include<sys/types.h>
#include<fcntl.h>
int main(){
pid_t chpid;
int fd,variable,status;
char ch;
variable=9;
if(fd=open("hello.c",O_RDONLY)==-1) {
printf("unable to open hello.c\n");
return 1;
}
chpid=fork();
if(chpid!=0) {
wait(&status);
}
else {
variable=42;
close(fd);
printf("the child has changed the value of variable to %d
\n",variable);
printf("the child has also closed the file\n");
return 0;
}
printf("the value of variable now is %d\n",variable);
if(read(fd,&ch,1)==-1) {
printf("READ Failed\n");
return 1;
}
else {
printf("Read from file %s",&ch);
}
return 0;
}
/*
*/
the output is as follows
the child has changed the value of variable to 42
the child has also closed the file
the value of variable now is 9
The first three lines are as expected. but after the program goes into
the read function second time it does not come out again Why?