Using the file descriptor table for a process, answer the following questions. N
ID: 3833986 • Letter: U
Question
Using the file descriptor table for a process, answer the following questions. Note: the dup(), pipe() , and open() system calls always use the lowest numbered available file descriptor posi-tion.
(a) Label which entries in Table 2 refer to stdin, stdout, andstderr
(b) Assume that stdin, stdout, and stderr are all open. Label in Table 3 what the file descriptor table would look like after the following code is executed:
int fd[2];
close(1);
pipe(fd);
(c) Assuming a fresh file descriptor table with only stdin, stdout, and stderr open, show in Table 4 the contents of file descriptor table after thefollowing code is executed:
close(2);
dup(1);
Explanation / Answer
Standard file descriptors(fd) and the corresponding standard streams
fd
stream
0
stdin
1
stdout
2
stderr
Using the file descriptor table for a process, answer the following questions. Note: the dup(), pipe() , and open() system calls always use the lowest numbered available file descriptor posi-tion.
(a) Label which entries in Table 2 refer to stdin, stdout, and stderr
0
1
2
3
4
5
stdin
stdout
stderr
(b) Assume that stdin, stdout, and stderr are all open. Label in Table 3 what the file descriptor table would look like after the following code is executed:
int fd[2];
close(1); // closing the stdin
pipe(fd); // opening new file descriptor fd[0], fd[1]
0
1
2
3
4
5
stdin
fd[0]
stderr
fd[1]
(c) Assuming a fresh file descriptor table with only stdin, stdout, and stderr open, show in Table 4 the contents of file descriptor table after thefollowing code is executed:
close(2); //closing the stderr
dup(1); // new file descriptor newfd is a duplicate of file descriptor 1 (stdout)
0
1
2
3
4
5
stdin
stdout
newfd(stdout)
fd
stream
0
stdin
1
stdout
2
stderr
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.