Commit 37ee7fb4 authored by Jules Sang's avatar Jules Sang
Browse files

question 4 implemented

parent 217ea841
......@@ -130,24 +130,43 @@ int main() {
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) {
//}
if(read_cell) {
int status;
pid_t res = waitpid(read_cell->pid, &status, WNOHANG);
if(res != 0) {
// process ended, remove from list
// free(read_cell->command);
processes_list = read_cell->next;
free(read_cell->command);
free(read_cell);
read_cell = processes_list;
}
}
while (read_cell && read_cell->next) {
int status;
process_cell* next = read_cell->next;
pid_t res = waitpid(next->pid, &status, WNOHANG);
if(res != 0) {
// process ended, remove from list
// free(next->command);
read_cell->next = next->next;
free(next->command);
free(next);
}
read_cell = read_cell->next;
}
//print processes' list
printf("%20s %50s %10s\n", "PID", "Command", "Dead");
printf("%20s %50s\n", "PID", "Command");
// read_cell = processes_list;
read_cell = processes_list;
while (read_cell) {
int status;
pid_t res = waitpid(read_cell->pid, &status, WNOHANG);
int terminated = WIFEXITED(status);
// int terminated = WIFEXITED(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);
printf("%20d %50s\n", read_cell->pid, read_cell->command);
read_cell = read_cell->next;
}
printf("\n");
......
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