Hi,
I am trying to run the following piece of code. It compiles fine
[root@localhost test]# gcc -o prog prog.c
[root@localhost test]#
Code:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main()
{
int n;
int nread;
char s[15];
n = open("/dev/tty", O_RDWR);
nread = read(n, s, 10);
write(n, s, nread);
}
But when I run it:
[root@localhost test]# echo abcd|./prog
Hello
// halts here. comes to prompt after pressing Ctrl+c
When I replace
Code:
nread = read(n, s, 10);
write(n, s, nread);
with
Code:
nread = read(0, s, 10);
write(0, s, nread);
it works fine.
What is the scenario if I try to read from /dev/tty?
Thanks and regards,
Arun