//
//  Fichier : Question_02.cxx
//
//  cree le : 27/11/1999
//
//  par     : D. Mathieu
//
//  Contenu : Test de TPs systeme 2 - question 1
//
#include <string>
#include <unistd.h>     //  execlp()

#include "CExc.h"
#include "nsSysteme.h"

int ppal (int argc, char * argv []) throw (CExc)
{
     if (1 != argc) throw CExc (string ("Usage : ") + argv [0]);

    int pfd [2];
    nsSysteme::pipe (pfd);

    if (nsSysteme::fork ())
    {
        nsSysteme::close (pfd [0]);
        nsSysteme::dup2  (pfd [1], 1);
        nsSysteme::close (pfd [1]);
        ::execlp ("exo_05a", "exo_05a", 0);
        throw CExcFctSyst ("execlp ()");
    }

    // Question 2.2

    if (nsSysteme::fork ())
    {
        nsSysteme::dup2  (pfd [1], 1);
        nsSysteme::close (pfd [1]);
        nsSysteme::dup2  (pfd [0], 0);
        nsSysteme::close (pfd [0]);
        ::execlp ("exo_05c", "exo_05c", 0);
        throw CExcFctSyst ("execlp ()");
    }
    nsSysteme::close (pfd [1]);
    nsSysteme::dup2  (pfd [0], 0);
    nsSysteme::close (pfd [0]);
    ::execlp ("exo_05b", "exo_05b", 0);
    throw CExcFctSyst ("execlp ()");

    return 0;

}  //  ppal()