Operating Systems
COMP 3430 Guderian
Copyright By PowCoder代写 加微信 powcoder
Same as fifos?
| did you know this is a pipe character?
Anonymous and named
There are 2 types of pipes
Anonymous and named pipes
There are 2 types of pipes
Anonymous – where the two processes are related somehow
Anonymous and named pipes
There are 2 types of pipes
Anonymous – where the two processes are related somehow
Named – a file (because unix)
Pipes are managed by the kernel
Buffers information between readers and writers
Writes are atomic – never interfered with by a context switch.
man 7 pipe
Anonymous pipes
This is how classic piping functions:
cat something.txt | sort | head | less
Anonymous pipes – how
man 2 pipe has an example! Modified example is available.
Element 0 is read, element 1 is write. Remember: forking copies the process image, including file descriptors!
Parent takes [1], closes[0]
Child takes [0] and closes[1]
Use read and write to communicate
read and write Write to a pipe, specify an amount
char words[] = “Hey”;
write(pipefd[1], words, strlen(words));
read and write
Read from a pipe, easiest (not optimal) 1 char at a time
read(pipefd[0], &buf, 1);
Anonymous pipes
Useful, but… a little old-school. Named pipes can be more flexible for us.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com