Printing Linux Environment using C Program


Linux provides each running program with an environment. The environment is a collection of variable/value pairs. Both environment variable names and their values are character strings. By convention, environment variable names are spelled in all capital letters. You’re probably familiar with several common environment variables already.

For instance:

USER contains your username.

HOME contains the path to your home directory.

PATH contains a colon-separated list of directories through which Linux searches for commands you invoke.

DISPLAY contains the name and display number of the X Window server on which windows from graphical X Window programs will appear.

//Printing the Execution Environment
#include <stdio.h>
/* The ENVIRON variable contains the environment. */
extern char** environ;
int main ()
{
char** var;
for (var = environ; *var != NULL; ++var)
printf (“%s\n”, *var);
return 0;
}

Comments

Popular Posts