> as u told i have written my pgm using pipe(),fork()&execl() as follows
> /* method to read program name and its i/p from a text file line by
> if(end of file)
> if( pipe(fdes) )
> if( (st=fork()) >= 0)
> if(st==0) /*CHILD */
> close(0); /* CLOSING STDIN */
> dup(fdes); /* MAKES FDES AS STDIN */
I generally recommend using dup2() rather than dup(), so that you can
specify the destination descriptor explicitly.
You should be closing fdes and fdes, there is no fdes.
> execl(prgm read from the file);
> else /* PARENT */
> /* loop to write inputs to pipe */
I'm not familiar with pwait() -- I assume it's a variant of wait(). You
could also use waitpid() to wait specifically for the PID in st.
That should be fdes. And you should probably do this *before*
calling wait(), since many programs don't exit until they read EOF on
> if(status == 0 )
> pgm success
> pgm failed
> } /* WHILE END */
> } /* MAIN END */
> In this i have the following doubts
> 1)is this logic is correct?(this is working fine.but i wanted to
> know whether this is memory efficient or not.)
See my embedded comments above.
Quote:> 2)if the program executed by child process becomes end less
> process(due to mismatch in I/O),How to trap it in the main process ?
There's no way to do this reliably. You can use a timeout, but that
could result in a false positive if the program is just taking a long
time to do its work.
Quote:> 3)How to send the o/p of parent & child process to 2 different
> curses window?
You need to hook the child process's stdout to a pipe. The parent
process can read from the pipe and then send this to a different curses
window than it writes its own output.
*** PLEASE post questions in newsgroups, not directly to me ***