I'm writing my minishell and I can't understand why execve doesn't work when calling pid_2 ?
My main task is to implement env | grep LANG
int main(void)
{
pid_t pid_1, pid_2;
int fd[2];
int status;
char *mass_1[] = {"env", NULL};
char *mass_2[] = {"grep", "LANG", NULL};
pid_1 = fork();
pipe(fd);
if (pid_1 == 0)
{
dup2(fd[1], 0);
close(fd[0]);
execve(mass_1[0], mass_1, NULL);
exit(1);
}
pid_2 = fork();
if (pid_2 == 0)
{
dup2(fd[0], 0);
close(fd[1]);
execve(mass_2[0], mass_2, NULL);
exit(1);
}
close(fd[0]);
close(fd[1]);
waitpid(pid_1, &status, WUNTRACED);
waitpid(pid_2, &status, WUNTRACED);
return (0);
}