Could a program read()
information from the terminal output using STDOUT_FILENO
file descriptor instead of STDIN_FILENO
?
I made some example:
void auxiliar_alrm() {
write(STDIN_FILENO, "Hello!\n", strlen("Hello\n"));
}
int main() {
signal(SIGALRM, auxiliar_alrm);
alarm(3);
char word[100];
read(STDOUT_FILENO, word, 100); //Program gets blocked here till a SIGALRM prints something on screen
//...
}
After that read()
, word
will store what the write
in the signal handler has written to the screen?
I tried this code and it doesn't work, but I'm wondering if I'm missing something to get this work.