Hello and welcome.
In this video session, let's discuss the environment of a process.
Each process has a set or a list of strings called as environment.
Each of these strings are in form of name and value pairs.
Thus, the environment represents a set of name value pairs that can be used to hold information.
The name in the list are referred to as environment variables, so this is called as a environment variable.
Let's see an example of this to understand the environment of a process.
This is a small program to list the environment of the process.
Here we have a global variable, environ, which holds all the list of environment that is used in the
process.
We loop through each of the list and print the environment.
Let's run this program to understand the environment of a process.
So let's compile the program and create output file called env one.
Now let's run the output file.
So when we run this program, the program will execute as a process.
And all the environment variables of this process is listed in this program.
Let's execute program to understand the output.
Once we run the program, we can see that we have environment variables.
This is the environment variables and this corresponds to the name value pair.
We can see the list of environment variables and corresponding value assigned to the environment variables.
So these are the different environment variables of a process.
And these environment variables are visible across the function within the process.
This means every function called within this process can access this environment variables and this
environment variables acts as a global variables.
Whereas in the previous session we saw a command line argument where the command line arguments are
limited only to the main function and the command line arguments are not visible outside the main function.
So this is one of the advantages of using environment variables, where we can share the information
across the functions within the process.
Now let's see one more example of environment variables.
In this case, let's see how to use git env.
We have the list of environment variables.
In order to get the value of this environment, variables we use get env.
Here we have to pass the environment variable that we need to get the value of, and it returns the
value of that environment variable.
So in this case when we say get env of path it returns the value that is associated with path variable.
For example, let's see the value of path and home environment variables.
The value of environment variable path is this.
And the environment the value of environment variable home is this.
Now let's compile this program and get the values of required environment variables.
Let's compile env two dot c.
Now we have compiled Env2 dot c and created output file called env2.
Let's run Env2.
Here.
Out of all the environment variables, we are getting the value of environment, variables, path and
home.
So the environment variables are name and value pairs.
Now let's see one more example.
In this example, let's see how to set a new environment.
Here.
In this example we are using the function called as put env.
And here we are creating a new environment variable called as param one and setting its value to 1024.
In this case we are setting the value inside the main function and we are calling call underscore func
one function.
And inside this function we are trying to read the value of param one.
Let's compile this and see the output to understand it.
We have compiled and created an output file called as env three.
Now let's run Env3.
If we see the output, we have created a new environment variable param one equal to 1024.
And we are reading the value of environment variables path home and param one.
We can see that environment variable Param1 value is 1024.
Now from main function we call the new function.
And inside the new function we are trying to get the value of Param1 environment variable using get
env.
And here we can see that we are getting the same value 1024, both inside the main function as well
as in the call underscore function function.
This means that environment variable is visible for a given process, and can be accessible from anywhere
inside the process, and it's accessible from different function within the process also.
In the next video session, we will begin a new session on memory allocation.
Thank you.