• Advertisement
Sign in to follow this  

waiting for multiple processes

This topic is 4886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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  

  • Advertisement