before merging with lucky

This commit is contained in:
hugogogo
2021-11-16 19:11:15 +01:00
parent 36766501ba
commit f70ee4bae0
2 changed files with 14 additions and 9 deletions

View File

@@ -5,6 +5,8 @@
- [what is a tty](https://www.howtogeek.com/428174/what-is-a-tty-on-linux-and-how-to-use-the-tty-command/)
- [really handling process](https://stackoverflow.com/questions/47489128/handling-signals-sigstp-sigcont-sigint-with-child-process)
- [signal in a child process](https://stackoverflow.com/questions/55190460/using-signals-in-a-child-process)
- [send signal to process and childs](https://linuxconfig.org/how-to-propagate-a-signal-to-child-processes-from-a-bash-script)
- commande utile pour tester les process parents et enfants : while true ; do ps -o pid,pgid,cmd -C bash ; sleep 0.1 ; echo "\n" ; done
```text
| BASH | MINISHELL |

View File

@@ -6,7 +6,7 @@
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
/* Updated: 2021/11/15 20:21:59 by hulamy ### ########.fr */
/* Updated: 2021/11/16 13:12:52 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
@@ -53,14 +53,13 @@ void execute_cmd(char **envp, t_cmd **cmd_arr, t_all *c)
{
pid_t pid;
pid_t wpid;
int status;
int wstatus;
int i;
int argc;
// put signal handling for SIGINT to ignore so parent process will not activate signal_handling_executiv while childs are in process
// c->signal_behaviour.sa_handler = SIG_IGN;
// sigaction(SIGINT, &c->signal_behaviour, NULL);
signal(SIGINT, SIG_IGN);
c->signal_behaviour.sa_handler = SIG_IGN;
sigaction(SIGINT, &c->signal_behaviour, NULL);
i = 0;
while(cmd_arr[i])
{
@@ -68,9 +67,8 @@ signal(SIGINT, SIG_IGN);
if (pid == 0)
{
// activate singal handling for execution mode
// c->signal_behaviour.sa_handler = sigint_handler_execution;
// sigaction(SIGINT, &c->signal_behaviour, NULL);
signal(SIGINT, sigint_handler_execution);
c->signal_behaviour.sa_handler = sigint_handler_execution;
sigaction(SIGINT, &c->signal_behaviour, NULL);
if (cmd_arr[i]->fd_in != 0)
dup2(cmd_arr[i]->fd_in, STDIN_FILENO);
if (cmd_arr[i]->fd_out != 1)
@@ -95,7 +93,12 @@ signal(SIGINT, SIG_IGN);
i++;
}
// waitpid pour la derniere commande (pour '$?')
while ((wpid = wait(&status)) > 0);
wpid = 1;
while (wpid > 0)
wpid = wait(&wstatus);
// to print a \n after execve was terminated by a signal
if (WIFSIGNALED(wstatus))
write(1, "\n", 1);
// put signal handling for sigint back to the signal handler for interactiv mode
c->signal_behaviour.sa_handler = sigint_handler_interactiv;
sigaction(SIGINT, &c->signal_behaviour, NULL);