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

First exec example

/* Exec/execl.c */
#include <stdio.h>
#include <unistd.h>

int main(int argc,char* argv[])
{
    printf("Using *execl* to exec ls -l...\n");
    execl("/bin/ls","ls","-l",NULL);
    printf("Program Terminated\n");
    return 0;
}

The above program illustrates the function of exec(). execl() is one of the family members of exec(), which is responsible for calling external programs.

First the program will print out Using *execl* to exec ls -l...

Then the program will execute /bin/ls program, with the supplied arguments.

After this step, the code of the process is changed to the target program and it never returns to the original code. As the result, the line Program Terminated is not printed.

PreviousProcess ExecutionNextEnvironment Variables

Last updated 4 months ago

Was this helpful?