Hi,
I was coding a shell for fun and I discovered a weird bahaviour when invoking bash like this :
Code:
bash -ic <some_command>
Basically instead of looping through, the program gets killed and I don't really know why. Could someone have an explanation ?
Here is the basic code :
Code:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
void loop_pipe (char***cmd)
{
pid_tpid,wpid;
intstatus;
pid=fork();
if(pid==0)
{
// Child process
if(execvp((*cmd)[0],*cmd)==-1)
perror("Command error");
exit(EXIT_FAILURE);
}
elseif(pid<0)
{
// Error forking
perror("Fork error");
}
else
{
// Parent process
do{
wpid=waitpid(pid,&status,WUNTRACED);
}while(!WIFEXITED(status)&&!WIFSIGNALED(status));
}
}
int main()
{
char*ls[]={"bash","-ic","uname",NULL};
char**cmd[]={ls,NULL};
while(1)
{
loop_pipe(cmd);
}
}
Thanks !