The concepts of processes and IO are generally disjunct. There are no signals that are exchanged between child and parent process, except for unix (kill) signals sent to the parent pid, that propagate to the children.
Waitpid just waits for termination of a child pid, returning its status code.
If you want to exchange data between parent and child you need to create a pipe
(see man -s 2 pipe
) between both processes, see the manual page for an example.
If you want to use scanf
(input from stdin) in the child, you need to bind the pipefd[0]
to the stdin file descriptor 0
(or STDIN_FILENO).
Now you can use select
or poll
in the parent process to check if the child is ready to read data sent by the parent to pipefd[1]
.
If you use printf
or some other stdio.h
method to write to the child (via STDOUT_FILENO for example), the IO on the parent might block anyway, even if select
or poll
told that the child is ready to receive the data, if the child reads too slow or stops reading too early and the output buffer is full (which has a default size of 4096 bytes, I think).
A unistd.h
write call might return a value
nw = write(pipefd[1], buffer, nbytes);
nw < nbytes
if the child did not read that many (nbytes
) bytes of input.
So be carefull with the tripping hazards when doing asynchronous communication. Check the CSP (Communicating Sequential Processes) method as a different and more stable approach to communication, that uses synchronous communication, when you understood the asynchronous methods.