#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <assert.h>

#include <iostream>
using namespace std;

int 
main()
{

    pid_t child_pid = fork();

    if (child_pid < 0)
    {
        perror("fork() failed: ");
        exit(1);
    }

    else if (child_pid == 0)
    {
        cout << "child about to call execl() ********" << endl;
        // NOTE: first argument is the file to execute
        //       subsequent arguments are command line args
        //       NULL terminate the list of command line args
        execl("/bin/ls", "ls", "-l", 0);
        // only reach this code if execl failed
        perror("execl() failed: ");
    }

    // only reach this part of the program if we are the parent

    assert(wait(NULL) == child_pid); // make sure wait() did not error
    cout << "parent after child finished *******" << endl;
    return 0;
}

