No subject


Tue Apr 3 04:48:41 UTC 2007


...
> void child (prog *run, char *runthis)
> {
>     close(STDOUT);
>     dup( run->cp[OUTPUT]);
>     close(STDIN);
>     dup(run->pc[INPUT]);

You should close and dup for stderr here as well, since any errors will go to
the tty, which could raise a SIGTTOU signal if the child process has been
disassociated from the tty.

>     close(run->pc[OUTPUT]);
>     close(run->cp[INPUT]);

  You're closing the parents descriptors here, like you should, but you do not
do the reverse of this in the parent.  Make the default action for the fork
close the run->cp[OUTPUT] and run-pc[INPUT] before you return from the
runthis() function.

>     execlp (runthis, NULL);
>     printf ("ERROR!\n");
>     exit(1);
> }
...

  You may also wish to look at socketpair(), which creates a bi-directional
socket/pipe which is less work to setup than multiple pipe()s.

								- Steve



More information about the linuxCprogramming mailing list