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: execv

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

execv() uses pathname, argument array and original ENV to execute the program.

execv("/bin/ls",arg);

You need to specify the absolute path for your target program and array of char* for the program arguments.

Lastly execv() uses original system environment variables for the new program.

Previousexec Family: execleNextexec Family: execvp

Last updated 4 months ago

Was this helpful?