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 error handling

If errors occur while executing exec*(), it will return to the program and continue execution. The return value is -1, and errno is set to indicate the error.

/* Exec/exec_error.c */
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
int main(int argc,char *argv[])
{
    printf("Try to execute lss\n");
    execl("/bin/lls","lls",NULL);
    printf("execl returned! errno is [%d]\n",errno);
    perror("The error message is :");
    return 0;
}

In this program, you can see the line execl returned!... is printed, indicating that execl() returns to the main function and the execution continues. errno is a global variable that stores the error number. You can check the manual for the error reason; however, you can print in a human-friendly way by using perror().

Previousexec Family: execveNextWait!

Last updated 4 months ago

Was this helpful?