Write a C program that forks two processes that print command-line arguments and environment variables.
Before your start coding, you can briefly read about environment variables in Linux here: https://www.geeksforgeeks.org/environment-variables-in-linux-unix/
Each process should echo all its command-line arguments and its entire environment list.
The parent process should:
- Print its process ID
The first process should:
- Print its process ID
- Call the
echoall
executable usingexecle
, which requires a pathname and a specific environment.execle
should pass two arguments toechoall
that are: "Bandicoot" and "Pacman".execle
should use the custom environment variables provided incustom_env
.
The second process should:
- Print its process ID
- Call the
echoall
executable usingexeclp
, which uses a filename.execlp
should pass one argument toechoall
that is: "Spyro".- The caller’s environment is automatically passed to the new program.
- For
execlp
to work, the path to the executable programechoall
should be in your system path. Read about how to set your$PATH
variable in Linux at https://opensource.com/article/17/6/set-path-linux. - Another reference for adding
$PATH
: https://zwbetz.com/how-to-add-a-binary-to-your-path-on-macos-linux-windows/ - You can create a directory
bin
and add/home/your_username/bin/
to your path. - For both exec calls, set the first argument,
argv[0]
in the new program, to be the filename component of the pathname. - We provided the program echoall.c that should be executed by both processes. Compile echoall.c and move the executable to a directory in your
$PATH
. - Refer to the sample output expected_output.txt as an example