Featured Post

Tuesday, July 26, 2016

UNIX program which inherits all the parent's environment to child process


/*  UNIX program to print environment variables */
/environdemo.c*/
#include<stdio.h>
#include<unistd.h>
extern char **environ;
void main()
{
   int i;
  for(i=0;environ[i];i+)
  {
    printf("\n %s",environ[i]);
  }
}
ouput: /home/anil/~cc environdemo.c
          /home/anil/~./a.out
           /prints all the environment variables */


  


/*UNIX program which inherits all the parent's environment to child process*/
/childenviron.c*/

#include<stdio.h>
#include<unistd.h>
extern char **environ;

void main()
{

   int i;
  fork();
  for(i=0;environ[i];i+)
  {
    printf("\n %s",environ[i]);
  }
}
ouput: /home/anil/~cc environdemo.c
          /home/anil/~./a.out
           /prints all the environment variables two times one by parent process and the other by 
           child       process because child inherits all the parent environment variables and code*/


execl family of system calls, environ variables, printing environment variables, inheriting parent address space to child

No comments:

Post a Comment