On 2015-05-31, Hongyi Zhao <
hongy...@gmail.com> wrote:
> Hi all,
>
> When I running my script, sometimes I noticed the errors similar to the
> following:
>
> /proc/6656/cmdline: No such file or directory
>
> Any hints on this issue?
TOCTOTOU race condition? Are you extracting a PID from the output of ps, and then
using it to explore /proc?
http://en.wikipedia.org/wiki/Time_of_check_to_time_of_use
Here, the "check" is the detection of the existence of a process, obtaining a PID.
And "use" is the use of that PID to access properties of the process.
By the time ps terminates, some of the processes which it listed may have
terminated.
Worse, the PIDs which were observed can already be recycled to new processes,
unrelated to the old: which means the /proc/<pid> which you access exists, but is
not the process you think it is.
This is going to be rare, but not impossible: it depends on how wide the PID
space is, how fast the macine is generating new processes, and how these
parameters relate to the sampling-to-use delay in your script. If the script hits
some unusual delay (stuck on some procedure that involves a network transaction, say)
it becomes more likely.