Commit 1b3cf6c8 authored by Jules Sang's avatar Jules Sang
Browse files

rendu

parent 7c97d47c
......@@ -49,21 +49,21 @@ process_cell *processes_list = NULL;
pid_t waited_child = 0;
static void sigchld_handler(int signum) {
// todo: global variable ?
int status;
pid_t pid;
// handle all zombie children
// handle each zombie children
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
char *ps_name;
if ((ps_name = get_ps_name(processes_list, pid))) {
// the process that sent SIGCHLD was a background ps
// the '\r' serves to delete the current line before writing on it
// the process that sent SIGCHLD was a background ps => a message should be displayed
// length of the prompt
int rl_len;
// cursor's position
int saved_point;
// the string containing the prompt's text
char *saved_line;
if (waited_child == 0) {
// no child waited means the correct prompt has to be redisplayed after
// the message
// no child waited means the correct prompt has to be redisplayed after the message
rl_len = rl_point + strlen(rl_prompt);
// save the user's cursor position
saved_point = rl_point;
......@@ -100,12 +100,16 @@ static void sigchld_handler(int signum) {
static void initialize_signals() {
// defines the actions to take on reception of a signal
struct sigaction act;
// the handler is sigchld_handler
act.sa_handler = &sigchld_handler;
// empty act's mask
sigemptyset(&(act.sa_mask));
// no flags
act.sa_flags = 0;
sigaction(SIGCHLD, &act, NULL);
}
// returns the number of commands in a cmdline
static int get_nb_seq(struct cmdline *l) {
int i = 0;
// count the length of l->seq
......@@ -115,6 +119,7 @@ static int get_nb_seq(struct cmdline *l) {
return i;
}
// executes the command/set of commands in l, and updates processes_list
void execute_command(struct cmdline *l, process_cell **processes_list) {
int nb_seq = get_nb_seq(l);
// we will need as many pids as there are command
......
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