lkml.org 
[lkml]   [2003]   [Sep]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: use O_DIRECT open file, when read will hang.
On Fri, 19 Sep 2003, Hugang wrote:

Your script cannot work.
Also, nothing hangs.

> Hello all:
>
> Steps to reproduce:
>
> rm -f /tmp/1.log
> touch /tmp/1.log
> echo << EOF > /tmp/hang.c
^^^^______ cat, not echo

> #include <sys/types.h>
> #include <asm/fcntl.h>
>
> main()
> {
> int i;
> char buf[1025];
>
> i = open("/tmp/1.log", O_RDONLY | 040000, 0);
> if ( i != -1) {
> read(i, buf, 1);
> }
> printf("'%s'", buf);
> }
> EOF
> gcc -o /tmp/hang /tmp/hang.c
> /tmp/hang
>
>

This is a `strace` of it working:

getpid() = 14243
open("/tmp/1.log", O_RDONLY|0x4000) = 3
read(3, "", 1) = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(4, 1), ...}) = 0
old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400aa000
ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(1, "\'\'", 2) = 2
munmap(0x400aa000, 4096) = 0
_exit(2) = ?

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (794.73 BogoMips).
Note 96.31% of all statistics are fiction.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:48    [W:0.072 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site