bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getline in /proc


From: Andrew J. Schorr
Subject: Re: getline in /proc
Date: Sat, 17 Sep 2005 12:05:19 -0400
User-agent: Mutt/1.4.1i

On Fri, Sep 16, 2005 at 02:15:18PM -0400, Simon Vaillancourt wrote:
> Hello,
>    I'm not sure if this is a gawk(using version 3.1.1) bug or a procfs 
> issue but but when doing a getline on a file that doesn't exist in 
> /proc, it loops forever, for example :
> 
> echo test | gawk 'BEGIN { while (getline < 
> "/proc/anypid/unexistingfile") {print "line="$0}}'
> 
> I stumbled on this while writing a process analysis tool, when a process 
> for which I am readins properties in /proc suddently dies, my script 
> goes crazy. I can work around this problem by copying the files in /tmp 
> before reading them.

I think the problem is that you need to check for a non-positive return
code from getline.  For example, this script loops forever:

   gawk 'BEGIN {while (getline < "/tmp/does.not.exist") print "yes"}'

But this one exits immediately:

   gawk 'BEGIN {while ((getline < "/tmp/does.not.exist") > 0) print "yes"}'

>From the man page:

   "The  getline command returns 0 on end of file and -1 on an error.  Upon
   an error, ERRNO contains a string describing the problem."

Regards,
Andy




reply via email to

[Prev in Thread] Current Thread [Next in Thread]