Commit e65cad52 authored by Jules Sang's avatar Jules Sang
Browse files

started question 4

parent d568d50f
......@@ -5,14 +5,7 @@
* Ce code est distribué sous la licence GPLv3+. *
*****************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "variante.h"
#include "readcmd.h"
#include "ensishell.h"
#ifndef VARIANTE
#error "Variante non défini !!"
......@@ -25,7 +18,6 @@
*/
#if USE_GUILE == 1
#include <libguile.h>
int question6_executer(char *line)
{
......@@ -70,6 +62,8 @@ int main() {
scm_c_define_gsubr("executer", 1, 0, 0, executer_wrapper);
#endif
struct process_cell* processes_list = NULL;
while (1) {
struct cmdline *l;
char *line=0;
......@@ -132,17 +126,54 @@ int main() {
}
pid_t pid;
switch(pid = fork()) {
case -1:
perror("fork:");
break;
case 0:
// son
execvp(l->seq[0][0], l->seq[0]);
if (!strcmp(l->seq[0][0],"jobs")){
//jobs code
// update processes' list
struct process_cell* read_cell = processes_list;
//while (read_cell) {
//}
//print processes' list
read_cell = processes_list;
printf("jobs lancé\n");
while (read_cell) {
int status;
printf("pid: %d\n", read_cell->pid);
while(1);
pid_t res = waitpid(read_cell->pid, &status, WNOHANG);
//todo: n'existe plus
int terminated = WIFEXITED(status);
// int terminated = 0;
printf("command: %s, PID : %i, terminated: %d, status: %d, waitpid: %d, exit status: %d\n", read_cell->command, read_cell->pid, terminated, status, res, WEXITSTATUS(status));
read_cell = read_cell->next;
}
return 0;
} else {
execvp(l->seq[0][0], l->seq[0]);
}
break;
default:
if(l->bg){
//father
if(!l->bg){
wait(NULL);
} else {
// background task --> add it to the list of background tasks
process_cell* current_cell = malloc(sizeof(struct process_cell));
current_cell->next = NULL;
current_cell->command = malloc(strlen(l->seq[0][0]) + 1);
current_cell->pid = pid;
strcpy(current_cell->command, l->seq[0][0]);
current_cell->next = processes_list;
processes_list = current_cell;
}
}
......
#ifndef ENSISHELL_H
#define ENSISHELL_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <libguile.h>
#include "variante.h"
#include "readcmd.h"
struct process_cell {
struct process_cell* next;
char* command;
pid_t pid;
};
typedef struct process_cell process_cell;
#endif
\ No newline at end of file
#ifndef VARIANTE_H
#define VARIANTE_H
#define LOGINS plichonl;sangj
#define SUJET 0
#define USE_GUILE 1
#define USE_GNU_READLINE 1
#define VARIANTE SUJET
#if VARIANTE == 0
#define VARIANTE_STRING "Jokers et environnement ; Limitation du temps de calcul"
#elif VARIANTE == 1
#define VARIANTE_STRING "Jokers étendus (tilde, brace) ; Pipes multiples"
#elif VARIANTE == 2
#define VARIANTE_STRING "Terminaison asynchrone ; Limitations du temps de calcul"
#elif VARIANTE == 3
#define VARIANTE_STRING "Temps de calcul ; Pipes multiples"
#elif VARIANTE == 4
#define VARIANTE_STRING "Jokers et environnement ; Pipes multiples"
#elif VARIANTE == 5
#define VARIANTE_STRING "Jokers étendus (tilde, brace) ; Limitation du temps de calcul"
#elif VARIANTE == 6
#define VARIANTE_STRING "Terminaison asynchrone ; Pipes multiples"
#elif VARIANTE == 7
#define VARIANTE_STRING "Temps de calcul ; Limitation du temps de calcul )"
#elif VARIANTE == 8
#define VARIANTE_STRING "Jokers et environnement ; Terminaison asynchrone ;"
#elif VARIANTE == 9
#define VARIANTE_STRING "Jokers étendus (tilde, brace) ; Temps de calcul ;"
#elif VARIANTE == 10
#define VARIANTE_STRING "Jokers et environnement ; Temps de calcul ;"
#elif VARIANTE == 11
#define VARIANTE_STRING "Jokers étendus (tilde, brace) ; Terminaison asynchrone ;"
#endif
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment