C IPC waiting for child
- by Gary
So I have a program which creates a child process and executes a command (for example, ls). The parent will then use pipes to send to and get from the child. This works fine when I'm inputting commands myself from the command line.
However, when the input comes from a file, it seems like the child doesn't have enough time to run and I get NULL when reading from the pipe - even though there will be information coming from it.
Short of using sleep(), is there a better way to make sure the child has run before trying to read from it?
Thanks a lot!