c - Why my pipe ends only when i send a SIGINT -


basicaly, im writing shell in c.. im trying implement pipe feature, done:

 > ls | cat -e | wc | wc -l  > 1 

but have problem when trying pipe more slower/longer execution.

indeed, when try pipe result of 'cat /dev/urandom', basicly waits...

> cat /dev/urandom | cat > 

but, when send sigint (with ctrl + c) stop it, prints on stdout resulted buffer..

when ctrl + c , cat /dev/urandom

so question is: should looking @ try fix ?

parts of pipe execution:

    int         exec_apipe(t_me *me, t_node *curs, int is_last) {     int     pfd[2];     int     pid;      if (pipe(pfd) == -1 || !curs)         return (0);     if (!(curs->pid = fork()))     {         dup2(me->fd_in, 0);         me->fd_in > 0 ? close(me->fd_in) : 0;         if (!is_last)             dup2(pfd[1], 1);         else if (curs->parent->parent && curs->parent->parent->fd_out >= 0)             dup2(curs->parent->parent->fd_out, 1);         close(pfd[0]);         exec_mpipe(me, curs);         exit(-1);     }     else if (curs->pid > 0)     {         waitpid(curs->pid, &(curs->ret), wuntraced);         handle_pid(me, curs->ret);         close(pfd[1]);         me->fd_in = pfd[0];     }     return (pid >= 0 ? 1 : -1); } 

i hope understand im saying, , maybe can help.. thanks

you need start all programs in pipeline before wait any of them complete.

your shell implementation waiting each pipeline element finish before starts next one. /dev/urandom endless stream; cat /dev/urandom run until killed. second cat never gets started until control-c first one.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -