From 87b9fab083df5209ac1eba83855c9084997f2210 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 12 Dec 2016 23:56:05 +0100 Subject: [PATCH] gonna add processes inside of job --- 42sh/includes/exec.h | 3 --- 42sh/includes/job_control.h | 23 +++++++++++++++++++---- 42sh/src/exec/exec_ampersand.c | 4 ++-- 42sh/src/exec/ft_cmd.c | 2 +- 42sh/src/parser/ft_parse.c | 3 ++- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index abe37ef9..cf9f0714 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -23,9 +23,6 @@ typedef long long t_type; struct s_exec { - int fdin; - int fdout; - int amp; char *aol_status; int aol_search; }; diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index 2e01ebf4..44f85489 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -17,19 +17,34 @@ # include # include "libft.h" -typedef struct s_job t_job; -typedef struct s_jobc t_jobc; +typedef struct s_job t_job; +typedef struct s_process t_process; +typedef struct s_jobc t_jobc; struct s_job { int id; - pid_t pid; + pid_t pgid; + char notified; char *command; + int foreground; + t_list *first_process; +}; + +struct s_process +{ + char **argv; + pid_t pid; + int fdin; + int fdout; + char completed; + char stopped; + int status; }; struct s_jobc { - t_list *list; + t_list *first_job; pid_t shell_pgid; int current_id; int rank[2]; diff --git a/42sh/src/exec/exec_ampersand.c b/42sh/src/exec/exec_ampersand.c index 4e3e48f7..41a5a3c6 100644 --- a/42sh/src/exec/exec_ampersand.c +++ b/42sh/src/exec/exec_ampersand.c @@ -14,9 +14,9 @@ int exec_ampersand(t_btree **ast) { - data_singleton()->exec.amp = 1; + data_singleton()->exec.foreground = 1; ft_exec(&(*ast)->left); - data_singleton()->exec.amp = 0; + data_singleton()->exec.foreground = 0; ft_exec(&(*ast)->right); btree_delone(ast, &ast_free); return (0); diff --git a/42sh/src/exec/ft_cmd.c b/42sh/src/exec/ft_cmd.c index 9dc9e546..cbb09dcc 100644 --- a/42sh/src/exec/ft_cmd.c +++ b/42sh/src/exec/ft_cmd.c @@ -55,7 +55,7 @@ int ft_cmd_exec(char *execpath, char **argv) { ft_strdel(&execpath); g_pid = pid; - if (data_singleton()->exec.amp) + if (data_singleton()->exec.foreground) job_new(argv, pid); else if (data_singleton()->exec.fdout == STDOUT) { diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 99565769..cd669aa6 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -14,8 +14,9 @@ t_parser g_parser[] = { - {TK_SEMI | TK_AMP, &parse_separator}, + {TK_SEMI, &parse_separator}, {TK_AND_IF | TK_OR_IF, &parse_separator}, + {TK_AMP, &parse_separator}, {TK_PIPE, &parse_separator}, {TK_LESS, &parse_less}, {TK_GREAT, &parse_great},