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]#
But when I run it: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); }
[root@localhost test]# echo abcd|./prog
Hello
// halts here. comes to prompt after pressing Ctrl+c
When I replace
withCode:nread = read(n, s, 10); write(n, s, nread);
it works fine.Code:nread = read(0, s, 10); write(0, s, nread);
What is the scenario if I try to read from /dev/tty?
Thanks and regards,
Arun



LinkBack URL
About LinkBacks



