**Trabalho Realizado na Semana #4**
**2 Lab Tasks**
**2.1 Task 1: Manipulating Environment Variables**
- Using the command `printenv` we got the following environment variables:

- Using the command `env |grep PWD` we got this particular environment variables:

- Using the command `export`:

- Using the command `unset` we didn't get anything printed
**2.2 Task 2: Passing Environment Variables from Parent Process to Child Process**

After compiling and runing the program printenv.c, we saved the outup into a file named *file*

After commenting out the printenv() statement in the child process case, and uncommenting the printenv() statement in the parent process case, we got the following output

Then, we used `diff`to compare the two output files.

Since we didn't get any output from this command we can conclude that the two files are the same, therefore the parent’s environment variables are inherited by the child process.
**2.3 Task 3: Environment Variables and execve()**

After running the program *myenv.c*, it didn't print out any environment variables, so the current process doesn't have any.

Then we change the invocation of `execve()`and now it printed environment variables.

In the first program, we are not preserving the old environment variables, because we are passing the object NULL.
In the second program, we pass`environ`which is a variable declared in`unistd.h`and it keeps track of the environment variables during the running of the current process.
**2.4 Task 4: Environment variables and system()**

After running the program *system.c* with the function call `system()`, with `/usr/bin/env"`as the only argument, the output showed all the environment variables.

This is because the `system()` function call uses `execl()` to execute */bin/sh; execl()*, calling `execve()` after that, passing to this new program all the environment variables, present on the output screen.
**2.5 Task 5: Environment Variable and Set-UID Programs**


We can see that all the environment variables we set using the command export in the parent shell process get into the Set-UID child process.
With this we can see that every environment variable that is created in a process gets passed down to all of its children processes.
**2.6 Task 6: The PATH Environment Variable and Set-UID Programs**