Commit 217ea841 authored by Jules Sang's avatar Jules Sang
Browse files

does not error on waitpid anymore but still cannot figure out which children...

does not error on waitpid anymore but still cannot figure out which children are dead... maybe use signal handlers ?
parent ee5a1334
......@@ -128,25 +128,29 @@ int main() {
pid_t pid;
// 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
// jobs code
// update processes' list
struct process_cell* read_cell = processes_list;
//while (read_cell) {
//}
//print processes' list
printf("%20s %50s %10s\n", "PID", "Command", "Dead");
// read_cell = processes_list;
while (read_cell) {
int status = 0;
pid_t res = waitpid(read_cell->pid, &status, WNOWAIT);
//todo: n'existe plus
int status;
pid_t res = waitpid(read_cell->pid, &status, WNOHANG);
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));
// 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));
printf("%20d %50s %10d\n", read_cell->pid, read_cell->command, res == -1 ? 1 : 0);
read_cell = read_cell->next;
}
printf("\n");
} else {
switch(pid = fork()) {
case -1:
......@@ -159,7 +163,7 @@ int main() {
default:
//father
if(!l->bg){
wait(NULL);
waitpid(pid, NULL, 0);
} else {
// background task --> add it to the list of background tasks
process_cell* current_cell = malloc(sizeof(struct process_cell));
......@@ -169,7 +173,6 @@ int main() {
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