LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices



Reply
 
Search this Thread
Old 04-24-2008, 02:34 PM   #1
Brian Moffet
LQ Newbie
 
Registered: Apr 2008
Posts: 1

Rep: Reputation: 0
Question /proc/<pid>/stat empty?


Good morning,

I've got an odd problem that I am trying to track down...

Kernel is 2.6.18 x86_64 SMP SUSE Linux.

We have some monitoring programs that watch processes. They do this
by looking in /proc/<pid>/stat and finding the SID, memory size,
etc... To do this, we use fopen, fscanf. In the case where the fscanf
fails, we do a rewind and fgets into a buffer so we can figure out
what was in the file (to improve debugging).

Occasionally, we see a successful fopen of the stat file, but the file
is empty.

It's been a while since I've looked at the proc fs code, but what I
remember is that if the stat file is able to be opened, there will
always be data in it. It will never be empty. If the process is gone
(cleaned up, not zombie) then the status would be "X".

Am I missing something here? Is there a case where the fopen would be
successful, yet the file has no contents?

I suspect a timing issue, but can't figure out what it would be.

Thanks,
Brian
 
Old 04-27-2008, 03:05 AM   #2
frostecheg
LQ Newbie
 
Registered: Apr 2008
Posts: 8

Rep: Reputation: 0
I would add something like system("cat /proc/<pid>/stat > /some_log_dir_path/log_<_filename_timestamp>"); , just to ensure it is not bug in your code, and the file is really empty.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading /proc/pid/stat file? sanjaykhuntia Linux - Enterprise 1 10-29-2007 03:45 AM
STAT() on directories of PROC ??? abhijit_awalekar Programming 2 09-07-2006 01:26 AM
/proc/<pid>/stat shows zero cpu usage simchac Linux - Kernel 0 07-25-2006 08:26 AM
/proc/stat cpu ahz Programming 1 04-24-2005 08:24 AM
about /proc/$pid/stat 's start time henryluo Programming 2 06-21-2004 10:15 AM


All times are GMT -5. The time now is 07:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration