Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 6-VO (15) Assume we have a file foo.txt that contains the six ASCIl characters abcdef and an empty file bar.txt include csapp.h int main

image text in transcribed
Problem 6-VO (15) Assume we have a file "foo.txt" that contains the six ASCIl characters abcdef and an empty file bar.txt include "csapp.h" int main ( pid t pid; char c: int fdl -Open ("foo.txt",RDONLY, 0) Read (Edl,&c, 1) int fd2 -Open ("bar.txt",O_WRONLY,0) printf("fdl - ed, fd2 - ed, c- %e ", fd1, fd2, c); if (pid-fork0) Read (fd1, c, 1); Dup2 (4, 1) printf ("fdi - td, fd2 - ed, c- %c ", fd1, fd2, c); exit(0) else ( Waitpid (pid, NULL, 0) Read (fdl, &c, 1): printf("fdi -ed, fd2 = ed, c-teln", fd1 , fd2 , c); (5 points) Draw the descriptor, open-file, and v-node tables for both parent/child processes just after the dup2(4, 1) line. You may assume the program started with just 0/1/2 file descriptors in the descriptor table for the process for stdin/stdout/stderr. 5 points) What would the contents of "bar.txt" be after this program executes? 5 points) What would be printed out to standard output after this program executes? 1.0 Problem 6-VO (15) Assume we have a file "foo.txt" that contains the six ASCIl characters abcdef and an empty file bar.txt include "csapp.h" int main ( pid t pid; char c: int fdl -Open ("foo.txt",RDONLY, 0) Read (Edl,&c, 1) int fd2 -Open ("bar.txt",O_WRONLY,0) printf("fdl - ed, fd2 - ed, c- %e ", fd1, fd2, c); if (pid-fork0) Read (fd1, c, 1); Dup2 (4, 1) printf ("fdi - td, fd2 - ed, c- %c ", fd1, fd2, c); exit(0) else ( Waitpid (pid, NULL, 0) Read (fdl, &c, 1): printf("fdi -ed, fd2 = ed, c-teln", fd1 , fd2 , c); (5 points) Draw the descriptor, open-file, and v-node tables for both parent/child processes just after the dup2(4, 1) line. You may assume the program started with just 0/1/2 file descriptors in the descriptor table for the process for stdin/stdout/stderr. 5 points) What would the contents of "bar.txt" be after this program executes? 5 points) What would be printed out to standard output after this program executes? 1.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

=+d. The price of sports utility vehicles rises.

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago