The goal of IPC is to communicate between different processes. Common ways to do IPC include:
> ls -1 | cut -d'.' -f1 | sort | uniq | tee dirents
int pipe(int pipefd[2]);
pipe()
takes a single argument - an array of size 2.pipefd[0]
to the reading end fd.pipefd[1]
to the writing end fd.How much data can a pipe hold?
Pipes' capacity depends on system configuration, but usually it ranges from 4 KiB to 128 KiB.
Check /proc/sys/fs/pipe-max-size
!
SIGPIPE
if all reading ends are closed.Note: SIGPIPE
kills your program by default. Catch or ignore it to see write()
returning -1 and setting errno
to EPIPE
.
pipe()
vs pipe2()
pipe2()
has an additional argument (flags
).
O_CLOEXEC
closes both pipe fds on a successful exec
.
reduce(A[1...n]) = reduce(reduce(A[1...n/2]) + reduce(A[n/2...n]))
Implement the MapReduce orchestrator:
No need to implement mappers or reducers yourself, and a splitter tool is already provided.
./mapreduce <input_file> <output_file> <mapper_executable> <reducer_executable> <mapper_count>
.
<mapper_count>
chunks using the given splitter
tool.