Advertisement

waiting for multiple processes

Started by October 01, 2004 06:00 PM
0 comments, last by abeylin 19 years, 11 months ago
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?
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.

http://www.mildspring.com - developing android games

This topic is closed to new replies.

Advertisement