I'm trying to open and read all proc/[pid]/stat file's content.
But I got ENOENT error from open func when pid >= 10961.
From proc manpage I found this :
In addition, if a process becomes a zombie (one that has been terminated by its parent with an exit call but has not been suspended by a wait call), most of its associated /proc files disappear from the directory structure. Normally, later attempts to open or to read or write to files that are opened before the process is terminated elicit the ENOENT message.
But I can still see content of file using cat command through path that occurs ENOENT.
This is confusing. Is this Zombie process or not? Why can't I open it?
code
void get_stat(char *path)
{
int fd;
char *res;
printf("path : %s\n", path);
fd = open(path, O_RDONLY);
if (fd < 0)
{
perror("open error");
exit(EXIT_FAILURE);
}
res = read_file(fd);
}
output
... worked fine before 10961 ...
path : /proc/6215/stat
path : /proc/6354/stat
path : /proc/10961/stat
open error: No such file or directory
path : /proc/12049/stat
open error: No such file or directory
path : /proc/12127/stat
open error: No such file or directory
path : /proc/12168/stat
open error: No such file or directory
path : /proc/12169/stat
open error: No such file or directory
path : /proc/12171/stat
open error: No such file or directory
path : /proc/12230/stat
open error: No such file or directory
path : /proc/12238/stat
open error: No such file or directory
path : /proc/13185/stat
open error: No such file or directory
path : /proc/13284/stat
open error: No such file or directory
path : /proc/13285/stat
open error: No such file or directory
path : /proc/13466/stat
open error: No such file or directory
path : /proc/13522/stat
open error: No such file or directory
path : /proc/13523/stat
open error: No such file or directory
path : /proc/13532/stat
open error: No such file or directory
path : /proc/13579/stat
open error: No such file or directory
path : /proc/13580/stat
open error: No such file or directory
path : /proc/13589/stat
open error: No such file or directory
path : /proc/13636/stat
open error: No such file or directory
path : /proc/13637/stat
open error: No such file or directory
path : /proc/13726/stat
open error: No such file or directory
path : /proc/14416/stat
open error: No such file or directory
path : /proc/15059/stat
open error: No such file or directory
path : /proc/15153/stat
open error: No such file or directory
path : /proc/15255/stat
open error: No such file or directory
path : /proc/15571/stat
open error: No such file or directory
path : /proc/15573/stat
open error: No such file or directory
path : /proc/15603/stat
open error: No such file or directory
path : /proc/15697/stat
open error: No such file or directory
path : /proc/15744/stat
open error: No such file or directory
path : /proc/15771/stat
open error: No such file or directory
path : /proc/15790/stat
open error: No such file or directory
EDIT : I get same result with sudo command.
I made path string through opendir/readdir func in same program. It only knows existing directory.
So some processe existed when getting their path name, and then vanished, and reappered.
Through cat, I found many of them have name 'kworker'.
Maybe that kind of process can behave like that? I'm searching now..