- Learn how to combine several processes in a pipeline using various system calls and pipes.
In this lab you are to write a program in C
that solves the same problem as in splab1
. The program should use the same tools that you used in splab1
, but the shell logic should be done by the C program itself. You should use system calls like fork
, exec*
, wait
/waitpid
, open
, close
, pipe
, dup2
, exit
/_exit
.
By shell logic we mean:
- forking processes and waiting results from them
- opening files and i/o redirection (using
pipe
) if
statements and loops (e.g.for
/while
) ofbash
.
Store your splab1
solution in ./solution/top and splab3
solution in ./solution/top.c.
- See example 1, C program
- See example 2, shell script with for loop, C program using
fdopen
function - See example 3, shell script with
awk
, C program withoutfdopen
man fdopen
man 2 fork
man 2 execve
man 2 waitpid
man 2 pipe
man 2 dup2
- OSTEP Chapter 5
- Chapters 6, 24-28 of Linux Programming Interface by Micheal Kerrisk
- Chapter 5 of Linux System Programming by Robert Love
- The task was adopted and adapted from http://vseloved.github.io/spos. All credits go to Vsevolod Dyomkin.
- Variants in Russian can be found there