- Write a program that creates a child process: the child process
executes the command "wc -l". The standard input of the command is
taken from the file /etc/passwd. The parent process waits for the
child to finish before continuing execution.
Goal: This exercise shows how the "<" operator should work.
Hint: Use fork(), exec(), wait() for process control, and open(),
close(), dup() for file operations.
- Write a program that creates a child process: the child process
executes the command "ls -l /". The standard output of the command is
sent to the file listroot.txt. The parent process waits for the
child to finish before continuing execution.
Goal: This exercise shows how the ">" operator should work.
Hint: Use creat() to create a new file or rewrite an existing one. It
is equivalent to open() with flags equal to O_CREAT|O_WRONLY|O_TRUNC,
but "mode" must be specified when O_CREAT is in the flags.
- Write a program that creates two children processes. The first
one sends its process ID to the second one through a pipe.
Goal: This exercise shows how to create two or more child processes,
and how to send a message through a pipe.
Hint: Use pipe() to create a pipe, and read(), write() to read from
/ write to the pipe.
- Write a program that creates two child processes. The first one
executes the command "ps ax". Its output is redirected to a pipe.
The second one executes the command "grep bash". Its input is
redirected from the pipe that the first process' output is written
to. So the overall command lists all the running "bash" shells.
Goal: This exercise shows how the "|" operator should work.
Hint: Redirect the first command's stdout to the pipe, while redirect
the second command's stdin from the pipe. Remember to close the write
end of the pipe so that "grep" won't wait for the input forever.
|