I'm having an issue with my assignment.
I have to read data from terminal in child process, after parent process dies. It is clearly written, that the parent process must die right after executing child process, so solutions that I found ( such as using wait()
) are not usefull for me.
My Code
int main(void)
{
printf("start main\n");
if(fork() == 0){
char buffer[64];
fgets(buffer, 64, stdin);
printf("Child process: %s\n", buffer);
}
else printf("end main\n");
//Using WAIT() here is not allowed in my assignment.
return 0;
}
It doesn't wait for me to enter data. It seems that after parent ends, child process is in the background and it can not read any data from terminal.
The Results
damian@damian-Virtualbox:-$ ./testuje
start main
end main
damian@damian-Virtualbox:-$ Child Process:
echo test | ./testuje
start main
end
damian@damian-Virtualbox:-$ Child Process: test
What Program should do
print: start main
print: end main
then it should:
wait for user to type something
print: child process: text_typed_by_user
EDIT: I was suggested to use tee
command. Do you have any idea how to use that to achive what I wanted?