Re: sed not working on /proc files

Harald Koenig (koenig@tat.physik.uni-tuebingen.de)
Tue, 27 Apr 1999 00:33:30 +0200


On Apr 26, Stefan Monnier wrote:

> How do you explain the following problem (with 2.2.6):
>
> # (sed 's/a/a/') </proc/modules
> # (cat | sed 's/a/a/') </proc/modules
> nfsd 147288 1 (autoclean)
> nfs 27856 2 (autoclean)
> lockd 29000 1 (autoclean) [nfsd nfs]
> sunrpc 48492 1 (autoclean) [nfsd nfs lockd]
> autofs 8872 1 (autoclean)
> 3c59x 17456 1 (autoclean)
> opl3 10264 0
> cs4232 2264 0
> ad1848 15152 0 [cs4232]
> uart401 5628 0 [cs4232]
> sound 55080 0 [opl3 cs4232 ad1848 uart401]
> soundcore 2208 6 [sound]
> binfmt_misc 3108 0
> st 23352 0
> softdog 948 1
> unix 10056 72 (autoclean)
> #
>
> It also happens on other /proc files (meminfo, tcp_syncookies, ...).

strace is your friend!

# strace -v sed 's/a/a/' /proc/modules
execve("/usr/bin/sed", ["sed", "s/a/a/", "/proc/modules"], [/* 67 vars */]) = 0
...
open("/proc/modules", O_RDONLY) = 3
fstat(3, {st_dev=makedev(0, 1), st_ino=0, st_mode=S_ISGID|S_ISVTX|0631, st_nlink=0, st_uid=1024, st_gid=0, st_blksize=925165771, st_blocks=0, st_size=0, st_atime=0, st_mtime=35/12/23-10:37:04, st_ctime=70/01/01-01:00:03}) = 0
^^^^^^^^^
^^^^^^^^^
mmap(0, 0, PROT_READ, MAP_PRIVATE, 3, 0) = 0
close(3) = 0
close(1) = 0
_exit(0) = ?

sed checks the size of /proc/modules and realizes that it's 0 bytes long,
so it's done with its job immedeately.

OTOH cat doesn't check or care about file size and just tries to read,
and it succeds to read (at least some bytes)...

Harald

--
All SCSI disks will from now on                     ___       _____
be required to send an email notice                0--,|    /OOOOOOO\
24 hours prior to complete hardware failure!      <_/  /  /OOOOOOOOOOO\
                                                    \  \/OOOOOOOOOOOOOOO\
                                                      \ OOOOOOOOOOOOOOOOO|//
Harald Koenig,                                         \/\/\/\/\/\/\/\/\/
Inst.f.Theoret.Astrophysik                              //  /     \\  \
koenig@tat.physik.uni-tuebingen.de                     ^^^^^       ^^^^^

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