EBK COMPUTER SYSTEMS
EBK COMPUTER SYSTEMS
3rd Edition
ISBN: 8220101459107
Author: O'HALLARON
Publisher: YUZU
Question
Book Icon
Chapter 10.9, Problem 10.4PP
Program Plan Intro

“dup2” function:

  • This function is used to copies the entry of old descriptor table to new descriptor table entry.
  • Format for “dup2” function is given below,

    int dup2(int oldFD, int newFD);

  • From the above format, “oldFD” means old descriptor table entry and “newFD” means new descriptor table entry.
    • It is used to copy the content of “oldFD” to “newFD”.
    • If “newFD” was already open, then “dup2” function closes the “newFD” before it copies “oldFD”.

Example:

The example for “dup2” function is shown below:

Consider the function “dup2(4, 1)”.

  • There are five file descriptors for given function that is “fd0”, “fd1”, “fd2”, “fd3”, and “fd4”. Each process in the LINUX begins life with three files they are
    • File descriptor “fd0” – standard input
    • File descriptor “fd1” – standard output
    • File descriptor “fd2” – standard error
  • For this function, assume two files such as “file A” and “file B”. Each file contains file table and v-node table.
    • The entries in file table are file position and reference count.
    • The entries in v-node table are file access, file size and file type.
  • Before calling “dup2(4, 1)”:
    • The “fd1” points to “file A” and “fd4” points to “file B”.
    • The reference count for both files are equal to “1”.
  • After calling “dup2(4, 1)”:
    • Both “fd1” and “fd2” corresponds to “file B”.
    • The “file A” has been closed and the entries in file table and v-node table of “file A” deleted.
    • The reference count for “file B” is incremented that is now reference count is “2”.
      • From the above description, any data written to standard output are redirected to “file B”.

Blurred answer
Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY