Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. We are trying to change the resources
  2.  
  3. Standard input is sourced not by the console, but by this array of letters. It has an infd that the parent can print to. All the text that the parent can put into it is vacuumed into the standard input.
  4.  
  5. The big mystery is how the text published through infd is shown in standard input through the child program.
  6.  
  7. The typedef we are going to code to is subprocess.t
  8.  
  9. typedef struct {
  10. pid_t pid;
  11. int infd;
  12. }subprocess.t
  13.  
  14. pipe
  15.  
  16. if proceeding the pipe call, you have an array of two file types. fds[1] can be written to, and fds[0] can be read. Whatever is published to fds[1] is written to and readable from fds[0]. Why would I go through a pipe to channel a string from one program to another?
  17.  
  18. If you rely on the fact that when a child process is forked off, file descriptors are replicated
  19.  
  20. If the declaration of this array of length 2 populates length 0-1 of this array, what if file descriptors 7-8 were linked to each other. Then, whatever is published to file descriptor 8 is read and written to file descriptor 7.
  21.  
  22. [8] -----> [7] (how the file descriptors are related)
  23. but then... if you call fork... you clone the file descriptors.
  24. fork()
  25.  
  26. child:
  27. [8] -----> [7]
  28.  
  29.  
  30. parent:
  31. [8] --> [7]
  32. \ /
  33. X
  34. / \
  35. / \
  36. [8] --> [7]
  37. child ^
  38.  
  39. ./pipe-experiment
  40.  
  41. [0][1][2][3][4][5]
  42.  
  43. filetable [0][1][2][3][4][5]
  44.  
  45. vnodetable [0][1][2][3][4][5]
  46.  
  47. whatever number is in fds[0].. sort doesnt know that. you can make it so fds[0] is NOT associated with those file resources
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement