slides05 Flashcards
1
Q
three streams in a process
A
- standard in (stream 0): default stream for input on keyboard
- standard out (stream 1): eg. terminal screen
- standard error (stream 2)
2
Q
File Descriptor Table
A
- each process has a unique FDT in the kernel space
- cloned during a fork
- index: File Descriptor
- 0th entry: stdnin
- 1st entry: stdout
- 2nd entry: stderr
3
Q
output redirection (printing to a file)
A
- close(1) dissociates FTD[1] from the terminal
- FDT[1] becomes available for use
- if we run int fd = open(“abc.txt”, ), we get fd = 1 (it looks for the first available slot from the top of FTD)
- now, whenever we call printf(), instead of displaying to the terminal, it will go into the file ‘abc.txt’
- the redirection is only valid for the current process, you can create a child at this point and it will inherit the redirection
4
Q
intput redirection
A
- close(0)
- open the file from which we want to receive the scanf() inputs
5
Q
command piping
A
- one process sends its output so it becomes an input to another process
- done using pipes
6
Q
pipe()
A
- creates a pipe
- two end points
- unidirectional data flow
- write end: pipe[1]; read end: pipe[0]
- inside the kernel, array of two fd descriptors
7
Q
sharing information between parent and child processes using pipe
A
- when you do a fork: FTD is copied to child process, pipe is exact same in both processes (not a copy)
- REVIEW
8
Q
socket
A
- endpoint provided by OS for communication
- pair of sockets acts as a communication link between processes
- identified by an address:port