56 lines
1 KiB
C
56 lines
1 KiB
C
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <sys/wait.h>
|
|
#include <string.h>
|
|
#include <signal.h>
|
|
#include <errno.h>
|
|
#include <setjmp.h>
|
|
#include "readcmd.h"
|
|
|
|
extern int errno;
|
|
|
|
struct cmdline *cmd;
|
|
|
|
int pid_fils;
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
// loop principal
|
|
while (1)
|
|
{
|
|
printf(">>> ");
|
|
cmd = readcmd();
|
|
|
|
if (cmd == NULL)
|
|
{ // EOF
|
|
break;
|
|
}
|
|
else if (cmd->seq[0] == NULL)
|
|
{ // empty
|
|
continue;
|
|
}
|
|
|
|
pid_fils = fork();
|
|
if (pid_fils == -1)
|
|
{ // fork fail ?
|
|
fprintf(stderr, "ERROR: forking failed, (%d) %s\n", errno, strerror(errno));
|
|
exit(errno);
|
|
}
|
|
|
|
if (pid_fils == 0)
|
|
{ // instructions du fils
|
|
execvp(cmd->seq[0][0], cmd->seq[0]);
|
|
exit(errno); // si execlp échoue on exit avec une erreur
|
|
}
|
|
else
|
|
{ // instructions du père
|
|
// rien
|
|
}
|
|
}
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|