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

started cleanup

parent d9491137
......@@ -101,7 +101,7 @@ configure_file (
# Si vous utilisez plusieurs fichiers, en plus de ensishell.c, pour votre
# shell il faut les ajouter ici
##
add_executable(ensishell src/readcmd.c src/ensishell.c)
add_executable(ensishell src/readcmd.c src/ensishell.c src/jobs.c)
target_link_libraries(ensishell ${READLINE_LDFLAGS} ${GUILE_LDFLAGS})
##
......
......@@ -6,6 +6,7 @@
*****************************************************/
#include "ensishell.h"
#include "jobs.h"
#ifndef VARIANTE
#error "Variante non défini !!"
......@@ -130,46 +131,7 @@ 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;
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\n", "PID", "Command");
read_cell = processes_list;
while (read_cell) {
// 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\n", read_cell->pid, read_cell->command);
read_cell = read_cell->next;
}
printf("\n");
jobs(processes_list);
} else {
switch(pid = fork()) {
case -1:
......
#include "jobs.h"
void jobs(process_cell* processes_list) {
struct process_cell* read_cell = processes_list;
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\n", "PID", "Command");
read_cell = processes_list;
while (read_cell) {
// 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\n", read_cell->pid, read_cell->command);
read_cell = read_cell->next;
}
printf("\n");
}
\ No newline at end of file
#ifndef JOBS_H
#define JOBS_H
#include "ensishell.h"
void jobs(process_cell* processes_list);
#endif
#!/usr/bin/python
while(True):
pass
\ No newline at end of file
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