LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-03-2007, 02:27 PM   #1
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Rep: Reputation: 30
Monitoring procfs


Hi All,

I need to monitor the changes in the procfs, in particular in /proc/net/tcp file. I tried inotify but it doesn't work with proc as it is not a regular file system. I need to catch the changes almost instantly. Any ideas?

Best,
Chris
 
Old 05-03-2007, 04:09 PM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Well, this is the programming forum, so you came to the right place.

Perl might be your best bet. Suck in the whole file (/proc/net/tcp) as though it were a regular file. Knock yourself out analyzing it. Then sleep for a second or five and do it all again.

Hope this helps.
 
Old 05-03-2007, 04:18 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Ahhhh - you sure this is really the way you want to do this ???.

Conceptually, the contents of a procfs "file" don't exist until you (userland) query it. The data is exposed in response to the query.
It doesn't "change" until you look.

Classic "observer effect" ...
 
Old 05-04-2007, 02:49 PM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Quote:
It doesn't "change" until you look.
Fine. That's all krizzz wants. Or am I missing your point?
 
Old 05-04-2007, 05:52 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally Posted by krizzz
I need to catch the changes almost instantly.
I was mainly responding to this bit.
Your solution will work depending on the frequency I guess.
 
Old 05-05-2007, 02:52 PM   #6
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
krizzz? Does this work for you?
 
Old 05-08-2007, 09:28 AM   #7
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Original Poster
Rep: Reputation: 30
Thank you for your answers and sorry for my delayed response. Yes, I know that I can't really monitor it in the real time. Let me give you some more details so you know what the actual problem is. I need to monitor the system sockets. In particular I have to discover the event of the new socket creation as immediately as possible. This is my goal. The problem is I have to do it from the user space with no kernel mods/patches/etc. involved whatsoever. I can't even use the hooks (similar to those that rootkits use) to "patch kernel" on fly and "replace" standard system calls to monitor the particular system call. I've gone through ptrace already but stumbled at the signaling issues which are pain to deal with when tracing multiple forks/vforks and all other flavors of sys_clone. Even strace doesn't deal with them correctly. So, if you have any other ideas they will be appreciated.

Thanks
Chris
 
Old 05-09-2007, 07:59 AM   #8
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
I don't think there's any magic bullet here. Just loop without sleeping, but nice() your user process down so you don't drag down everyone else.

This solution is sleezy and messy, and I don't like it. But I don't think there's any magic bullet.
 
Old 05-09-2007, 08:47 AM   #9
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 200

Original Poster
Rep: Reputation: 30
Thank you, I actually added a usleep() to ease down the polling intensity and the implementation seems just good enough for what I'm doing. BTW, could you think of any implementation involving stock kernel modules? I looked at kernel debugging and relayfs.
 
Old 05-10-2007, 06:29 PM   #10
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Kernel stuff? Outta my league here. Anyone else?
 
  


Reply



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
lm_sensors Can't access procfs/sysfs file humbletech99 Linux - Hardware 0 08-31-2006 06:40 AM
what is and why use PROCFS donoh Programming 1 05-30-2005 01:31 AM
HostAP and procfs shuuhen Linux - Wireless Networking 1 04-11-2005 01:22 AM
about procfs serji Linux - Software 1 12-04-2003 11:43 PM
procfs nullpt *BSD 1 10-25-2003 03:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 AM.

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
Open Source Consulting | Domain Registration