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

maybe it works on ensimag

parent e65cad52
......@@ -126,55 +126,52 @@ int main() {
}
pid_t pid;
switch(pid = fork()) {
case -1:
perror("fork:");
break;
case 0:
// son
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 {
// test if l->seq[0] is null in case of line return alone
if (l->seq[0] && strcmp(l->seq[0][0],"jobs") == 0){
//jobs code
// update processes' list
struct process_cell* read_cell = processes_list;
//while (read_cell) {
//}
//print processes' list
// read_cell = processes_list;
while (read_cell) {
int status = 0;
pid_t res = waitpid(read_cell->pid, &status, WNOWAIT);
//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;
}
} else {
switch(pid = fork()) {
case -1:
perror("fork:");
break;
case 0:
// son
execvp(l->seq[0][0], l->seq[0]);
}
break;
default:
//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;
}
break;
default:
//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;
printf("pid: %d\n", pid);
}
}
}
}
......
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