Question: Consider the following code snippet: int main 1 char * buf; char * str; int ret; int fd = open ( input . txt

Consider the following code snippet:
int main
1
char *buf; char *str;
int ret;
int fd = open("input. txt", O_CREAT | O_RDWR,0666);
pid_t pid = fork();
switch (pid){
case -1:
perror("Error: fork() error
"');
case 0:
printf("[Child] use [fd: %d]
", fd);
str = "Hello from the child";
ret = write(fd, str, strlen(str));
printf("[Child] write %s [ret: %d]
", str, ret);
fflush(stdout) ;
close(fd);
break;
default:
printf("[Parent] use [fd: %d]/[child pid: %d]
", fd, pid);
buf =(char *) malloc(20* sizeof(char));
sleep(2);
Iseek(fd,-20, SEEK_CUR);
ret = read(fd, buf, 20);
printf("[Parent] read %s [ret: %d]
"
, buf, ret);
fflush(stdout);
break;
return 0;
}
Which of the following statements is/are false (choose all that apply)?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!