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

exec Family: execle

/* Exec/execle.c */
#include <stdio.h>
#include <unistd.h>
int main(int argc,char *argv[])
{ 
    char *env[] = {"LS_COLORS=fi=04;33;44",NULL}; 
    printf("Using *execle* to exec ls -l\n"); 
    execle("/bin/ls","ls","-l","--color",NULL,env); 
    printf("Program Terminated\n");
    return 0;
}

execle() uses pathname, argument list and provided ENV to execute the program.

execle("/bin/ls","ls","-l","--color",NULL,env);

You need to provide the exact location (pathname) in order to execute it.

For the arguments, they are specified directly in the execle() function.

You can define new environment variables in the function. The environment variables are in a char* array. In this example, the behavior of ls can be changed by the variables. In this case, the colors for displaying files and directories are changed.

Previousexec Family: execlpNextexec Family: execv

Last updated 4 months ago

Was this helpful?