Sign in to follow this  
chadmv

waiting for multiple processes

Recommended Posts

I'm writing a basic shell that just executes commands through a program (the shell). I've implemented piping, but sometimes I get incorrect output with the same command. For example, If file has 2 lines.
sort < file | head -1 | cat -n
should print 1 line but sometimes it prints both lines as shown below: myshell: sort < file | head -1 | cat -n 1 This is line 1 myshell: sort < file | head -1 | cat -n 1 This is line 1 myshell: sort < file | head -1 | cat -n 1 This is line 1 2 This is line 2 At this point the prompt doesn't reappear. I do call wait(&status) 3 times. Any suggestions or ideas?

Share this post


Link to post
Share on other sites
You probably have a bug in the way you set your STDIN or STDOUT for those processes.
Maybe you are sometimes setting the STDOUT of the "sort" to STDIN of the "cat".

Or actually maybe the "head" process starts before the "sort" (are you using threads?) and so the STDIN is empty, so it terminates before the sort has a chance of sending it's output.

Share this post


Link to post
Share on other sites
Sign in to follow this