Group: comp.lang.c · Group Profile
Author: smartysmarty Date: May 13, 2008 00:11
can any one tell me what's wrong with this program?
#include
#include
main()
{
int pid,fd,pd;
pid=fork();
char *data,*str="child writes to the file";
if(pid == 0)
{
printf("IN CHILD\tcreating a file to COMMUNICATE\n");
fd=open("sarma.c",O_CREAT|O_APPEND|O_RDWR);
perror("OPEN OPERATION");
write(fd, str , 50);
perror("WRITE OPERATION");
fsync(fd);
perror("FSYNC OPERATION");
close(fd);
printf("child bids farewell\n");
}
else
{
printf("IN PARENT\tSLEEPING................\n");
wait(0);
printf("IN PARENT\topening the file to COMMUNICATE\n");
pd=open("sarma.c",O_RDONLY);
perror("OPEN OPERATION");
read(pd,data,50);
perror("READ OPERATION");
close(pd);
printf("PARENT reads:\"%%s\"\n",data);
printf("PARENT dies......\n");
}
}
The parent is reading the shared file but with an "illegal file
access" error.....
Check out the result on my system
IN PARENT SLEEPING................
IN CHILD creating a file to COMMUNICATE
OPEN OPERATION: Success
WRITE OPERATION: Illegal seek
FSYNC OPERATION: Illegal seek
child bids farewell
IN PARENT opening the file to COMMUNICATE
OPEN OPERATION: Success
READ OPERATION: Illegal seek
PARENT reads:"child writes to the file"
PARENT dies......
Segmentation fault
what is this segmentation fault for?
|