lab4 Process
  • Introduction
  • Knowing about process
    • Checking System Process
    • Process Identification
  • Let's Fork! Process Creation
    • Background of Process Creation
    • fork system call
    • Distinguish Parent and Child Process
    • Exercises
  • Process Execution
    • First exec example
    • Environment Variables
    • exec Family
    • exec Family: execlp
    • exec Family: execle
    • exec Family: execv
    • exec Family: execvp
    • exec Family: execve
    • exec error handling
  • Wait!
    • Problem 1: Without Wait?
    • Sleep
    • Problem 2: Zombies!
    • Wait System Call
    • waitpid
Powered by GitBook
On this page

Was this helpful?

  1. Process Execution

Environment Variables

In the shell, the environment variables are a set of strings that stores the settings, for example, PATH variable stores the path searching setting and http_proxy sets the proxy server setting.

There are many ways to get environment variables. One of the ways is from the argument of main function.

/* Exec/env.c */
#include <stdio.h>
int main(int argc,char *argv[], char* envp[])
{ 
    int i; 
    for (i = 0; envp[i];i++) 
    { 
        printf("[%d]: %s\n",i,envp[i]);
    } 
    return 0;
}

Take a note of the main function parameter. There is an extra item of char * envp[]. This allows the program to retrieve the system environment variable.

PreviousFirst exec exampleNextexec Family

Last updated 4 months ago

Was this helpful?