Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
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
Students have asked these similar questions
(In java please) ( NO TOY CLASS PLEASE READ INSTRUCTION OR DOWN VOTE PLEASE LOOK AT TWO IMAGES BELOW FIRST ONE IS CURRENCY CLASS NEED THE SECOND IS INSTRUCTIONS ON HOW TO MAKE TEST CLASS. PLEASE NO TOY CLASS OR DOWN VOTE USE CURRENCY CLASS INSTEAD AND UPDATE IT) THIS A LinkNode structure or class which will have two attributes - a data attribute, and a pointer attribute to the next node. The data attribute of the LinkNode should be a reference/pointer of the Currency class of Lab 2. Do not make it an inner class or member structure to the SinglyLinkedList class of #2 below. A SinglyLinkedList class which will be composed of three attributes - a count attribute, a LinkNode pointer/reference attribute named as and pointing to the start of the list and a LinkNode pointer/reference attribute named as and pointing to the end of the list. Since this is a class, make sure all these attributes are private. The class and attribute names for the node and linked list are the words in bold in #1…
(Chapter 10) Here again is the example used in our lecture to show the difference between scoping with blocks and dynamic scoping; fun g x =  let    val inc = 1;    fun f y = y + inc;    fun h z =      let        val inc = 2;      in        f z      end;  in    h x  end;   Annotate it as follows: Draw a circle around every block, and number the blocks. Identify each definition of a name. For each definition, describe its scope in terms of your block numbers. For each occurrence of a name (other than a definition of that name), show which definition is used to bind it. Check that this agrees with your scopes.
(In java please) ((please read instruction and look at the images please i keep getting wrong anwser no toy class)PLEASE i beg NO TOY CLASS PLEASE READ INSTRUCTION OR DOWN VOTE PLEASE LOOK AT TWO IMAGES BELOW FIRST ONE IS CURRENCY CLASS NEED THE SECOND IS INSTRUCTIONS ON HOW TO MAKE TEST CLASS. PLEASE NO TOY CLASS OR DOWN VOTE USE CURRENCY CLASS INSTEAD AND UPDATE IT) THIS A LinkNode structure or class which will have two attributes - a data attribute, and a pointer attribute to the next node. The data attribute of the LinkNode should be a reference/pointer of the Currency class of Lab 2. Do not make it an inner class or member structure to the SinglyLinkedList class of #2 below. A SinglyLinkedList class which will be composed of three attributes - a count attribute, a LinkNode pointer/reference attribute named as and pointing to the start of the list and a LinkNode pointer/reference attribute named as and pointing to the end of the list. Since this is a class, make sure all these…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning